diff --git a/README.rst b/README.rst index 5d93d03..61405ca 100644 --- a/README.rst +++ b/README.rst @@ -62,20 +62,25 @@ run:: ./install.sh +or:: + + ./install.zsh + +depending on your shell. Enter your root password if it asks. Add the line:: source /etc/profile -to ``~/.bashrc`` if it isn't already there. +to ``~/.bashrc`` or ``~/.zshrc`` if it isn't already there. Troubleshoot ------------ If the script fails, you may need to do:: - chmod +x install.sh + chmod +x install.(z)sh before the first step. @@ -86,7 +91,7 @@ Manual installation of autojump is very simple: copy - autojump.sh to /etc/profile.d, - autojump.1 to /usr/share/man/man1. -Make sure to source ``/etc/profile`` in your ``.bashrc``:: +Make sure to source ``/etc/profile`` in your ``.bashrc`` or ``.zshrc`` :: source /etc/profile diff --git a/_j b/_j new file mode 100644 index 0000000..81d1951 --- /dev/null +++ b/_j @@ -0,0 +1,11 @@ +#compdef j + +cur=${words[2, -1]} + +ret=$(autojump --completion "${cur[*]}") + +if [ "$ret" != "" ]; then # if at least one answer + for i in $(echo "$ret"); do + compadd -U $i # add all of them as possible completion + done +fi diff --git a/autojump b/autojump index 5b353ba..6b67b9f 100755 --- a/autojump +++ b/autojump @@ -75,8 +75,9 @@ except IOError: path_dict={} if ('-a','') in optlist: - dicadd(path_dict,args[-1]) - save(path_dict,dic_file) + if(args[-1] != os.path.expanduser("~")): # home dir can be reached quickly by "cd" and may interfere with other directory + dicadd(path_dict,args[-1]) + save(path_dict,dic_file) elif ('--stat','') in optlist: a=path_dict.items() a.sort(key=lambda e:e[1]) diff --git a/autojump.sh b/autojump.sh index 2202663..6635380 100755 --- a/autojump.sh +++ b/autojump.sh @@ -1,5 +1,6 @@ -#Source autojump.bashrc only if we're on bash, as it is -#not compatible with other shells +# Source autojump on BASH or ZSH depending on the shell if [ "$BASH_VERSION" ] && [ -n "$PS1" ] && echo $SHELLOPTS | grep -v posix >>/dev/null; then . /etc/profile.d/autojump.bash +elif [ "$ZSH_VERSION" ] && [ -n "$PS1" ]; then + . /etc/profile.d/autojump.zsh fi diff --git a/autojump.zsh b/autojump.zsh new file mode 100755 index 0000000..08cb4a7 --- /dev/null +++ b/autojump.zsh @@ -0,0 +1,7 @@ +function preexec() { + (autojump -a "$(pwd -P)"&)>/dev/null +} + +alias jumpstat="autojump --stat" + +function j { new_path="$(autojump $@)";if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; cd "$new_path";fi } diff --git a/install.zsh b/install.zsh new file mode 100755 index 0000000..899e871 --- /dev/null +++ b/install.zsh @@ -0,0 +1,37 @@ +#! /bin/zsh +# applet icon +sudo mkdir -p /usr/share/autojump/ +sudo cp icon.png /usr/share/autojump/ + +# scripts +sudo cp jumpapplet /usr/bin/ +sudo cp autojump /usr/bin/ + +# man pages +sudo cp autojump.1 /usr/share/man/man1/ + +# autocompletion file in the first directory of the FPATH variable +cp _j $(echo $FPATH | cut -d":" -f 1) + + +if [ -d "/etc/profile.d" ]; then + sudo cp autojump.zsh /etc/profile.d/ + sudo cp autojump.sh /etc/profile.d/ + echo "Remember to add the line" + echo " source /etc/profile" + echo "to your ~/.zshrc if it's not there already" +else + echo "Your distribution does not have a /etc/profile.d directory, the default that we install one of the scripts to. Would you like us to copy it into your ~/.zshrc file to make it work? (If you have done this once before, delete the old version before doing it again.) [y/n]" + read ans + if [ ${#ans} -gt 0 ]; then + if [ $ans = "y" -o $ans = "Y" -o $ans = "yes" -o $ans = "Yes" ]; then + echo "" >> ~/.zshrc + echo "#autojump" >> ~/.zshrc + cat autojump.zsh >> ~/.zshrc + else + echo "Then you need to put autojump.zsh, or the code from it, somewhere where it will get read. Good luck!" + fi + else + echo "Then you need to put autojump.zsh, or the code from it, somewhere where it will get read. Good luck!" + fi +fi