summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonid Volnitsky <Leonid@Volnitsky.com>2009-12-09 12:33:19 +0200
committerLeonid Volnitsky <Leonid@Volnitsky.com>2009-12-09 12:45:45 +0200
commitfc4b088cbec7d55d1bd8471807beb3f089cc4f22 (patch)
tree18e7f02ab427f21d5bd5fa0f98c461eab7bae4bd
parentreverted prompt char to old default '>' (diff)
downloadgit-prompt-fc4b088cbec7d55d1bd8471807beb3f089cc4f22.tar.gz
git-prompt-fc4b088cbec7d55d1bd8471807beb3f089cc4f22.tar.bz2
git-prompt-fc4b088cbec7d55d1bd8471807beb3f089cc4f22.zip
simple autojump
See description of autojump on github It is only ~10 lines of code, there is no database. It remembers only directories from current session. It select not most frequent dir, but matching last visited. Matches are done from beginning of of dir. cd /tmp cd "~/long dir mp3" cd "~/long dir mp4" cd /tmp cd /var/tmp cd /etc j t # same as cd /var/tmp j .*3 # same as cd "~/long dir mp3"
-rwxr-xr-xgit-prompt.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/git-prompt.sh b/git-prompt.sh
index 5a7591c..ccb16bd 100755
--- a/git-prompt.sh
+++ b/git-prompt.sh
@@ -54,6 +54,8 @@
max_file_list_length=${max_file_list_length:-100}
upcase_hostname=${upcase_hostname:-on}
+ aj_max=20
+
##################################################################### post config
@@ -587,6 +589,22 @@ enable_set_shell_label() {
set_shell_label $BASH_COMMAND' DEBUG >& /dev/null
}
+# autojump (see http://wiki.github.com/joelthelion/autojump)
+j (){
+ : ${1? usage: j dir-beginning}
+ # go in ring buffer starting from current index. cd to first matching dir
+ for (( i=(aj_idx+1)%aj_max; i != aj_idx%aj_max; i=++i%aj_max )) ; do
+ #echo == ${aj_dir_list[$i]} == $i
+ if [[ ${aj_dir_list[$i]} =~ ^.*/$1[^/]*$ ]] ; then
+ cd "${aj_dir_list[$i]}"
+ return
+ fi
+ done
+ echo '?'
+}
+
+alias jumpstart='echo ${aj_dir_list[@]}'
+
###################################################################### PROMPT_COMMAND
prompt_command_function() {
@@ -603,6 +621,11 @@ prompt_command_function() {
parse_vcs_status
+ # autojump
+ if [[ ${aj_dir_list[aj_idx%aj_max]} != $PWD ]] ; then
+ aj_dir_list[++aj_idx%aj_max]="$PWD"
+ fi
+
# if cwd_cmd have back-slash, then assign it value to cwd
# else eval cwd_cmd, cwd should have path after exection
eval "${cwd_cmd/\\/cwd=\\\\}"