+_ipython() {
+ # These guys keep changing their CLI because they hate their users.
+ local cmd=$1; shift
+ local args=(
+ --no-banner
+ --no-confirm-exit
+ --pdb
+ --nosep
+ --term-title
+ --pprint
+ )
+
+ case $(command ${cmd} --version) in
+ 0*) ;;
+ [123]*)
+ args+=(
+ --PromptManager.in_template='>>> '
+ --PromptManager.out_template=''
+ --PromptManager.justify=False
+ )
+ ;;
+ esac
+
+ command ${cmd} "${args[@]}" "$@"
+}
+ipython() { _ipython ${FUNCNAME}; }
+ipython2() { _ipython ${FUNCNAME}; }
+ipython3() { _ipython ${FUNCNAME}; }
+
+adk_path() {
+ local adk=/usr/local/src/android/adk/current/sdk
+ PATH+=":${adk}/tools:${adk}/platform-tools"
+}
+
+pd() {
+ if [[ $# -eq 0 ]] ; then
+ popd
+ elif [[ $# -eq 1 && $1 == "--" ]] ; then
+ dirs -v
+ else
+ pushd "$@"
+ fi
+}
+
+cd_history() {
+ if [[ $# -eq 1 ]] ; then
+ case $1 in
+ -h)
+ command dirs "$1" |& tail -1
+ command cd "$1" |& tail -1
+ return
+ ;;
+ --help)
+ command dirs "$1"
+ command cd "$1"
+ return
+ ;;
+ -[clpv])
+ command dirs "$1"
+ return
+ ;;
+ -[0-9]*)
+ set -- "$(dirs "+${1:1}")"
+ ;;
+ esac
+ fi
+
+ if command cd "$@" ; then
+ pushd -n "${PWD}" >/dev/null
+ else
+ local ret=$?
+
+ if [[ $# -gt 1 ]] ; then
+ # The `cd` above should have shown an error message for us.
+ local arg first_arg="$1"
+ while [[ $# -gt 0 ]] ; do
+ arg="$1"
+ shift
+ if [[ -d ${arg} ]] ; then
+ if [[ $# -gt 0 ]] ; then
+ printf 'cd: remaining: %s\n' "$@" >&2
+ fi
+ printf 'cd: entering: %s\n' "${arg}" >&2
+ cd_history "${arg}"
+ return
+ else
+ printf 'cd: skipping: %s\n' "${arg}" >&2
+ fi
+ done
+ # If we're still here, then we didn't cd anywhere.
+ echo "cd: cwd is unchanged!" >&2
+ fi
+
+ return ${ret}
+ fi
+}
+alias cd='cd_history'
+