From fc4b088cbec7d55d1bd8471807beb3f089cc4f22 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Wed, 9 Dec 2009 12:33:19 +0200 Subject: 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" --- git-prompt.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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=\\\\}" -- cgit v1.2.3