From a6410994c28a034acb88c84894fe1af11a9afc01 Mon Sep 17 00:00:00 2001 From: xiaonaitong Date: Wed, 14 Sep 2011 13:56:30 +0800 Subject: [PATCH 1/8] quick fix so thant it works on mingw and bash 3.1 --- autojump | 35 ++++++++++++++++++----------------- autojump.bash | 18 +++++++++++------- install.sh | 20 ++++++++++---------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/autojump b/autojump index 7b3aaf4..114dd61 100755 --- a/autojump +++ b/autojump @@ -55,23 +55,24 @@ def save(path_dict, dic_file): a backup file.""" # If the dic_file exists, check that it belongs to us # Otherwise, fail quietly - if (not os.path.exists(dic_file)) or os.getuid() == os.stat(dic_file)[4]: - temp = NamedTemporaryFile(dir=CONFIG_DIR, delete=False) - pickle.dump(path_dict, temp, 2) - temp.flush() - os.fsync(temp) - temp.close() - #cf. http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/ - os.rename(temp.name, dic_file) - try: #backup file - import time - if (not os.path.exists(dic_file+".bak") or - time.time()-os.path.getmtime(dic_file+".bak")>86400): - import shutil - shutil.copy(dic_file, dic_file+".bak") - except OSError as ex: - print("Error while creating backup autojump file. (%s)" % - ex, file=stderr) + temp = NamedTemporaryFile(dir=CONFIG_DIR, delete=False) + pickle.dump(path_dict, temp, 2) + temp.flush() + os.fsync(temp) + temp.close() + #cf. http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/ + #os.rename(temp.name, dic_file) + import shutil + shutil.copy(temp.name, dic_file) + try: #backup file + import time + if (not os.path.exists(dic_file+".bak") or + time.time()-os.path.getmtime(dic_file+".bak")>86400): + import shutil + shutil.copy(dic_file, dic_file+".bak") + except OSError as ex: + print("Error while creating backup autojump file. (%s)" % + ex, file=stderr) def forget(path_dict, dic_file): """Gradually forget about directories. Only call diff --git a/autojump.bash b/autojump.bash index aad91a8..59d0cb9 100644 --- a/autojump.bash +++ b/autojump.bash @@ -19,10 +19,11 @@ _autojump() { local cur cur=${COMP_WORDS[*]:1} - while read i + comps=$(autojump --bash --completion $cur) + for i in $comps do COMPREPLY=("${COMPREPLY[@]}" "${i}") - done < <(autojump --bash --completion $cur) + done } complete -F _autojump j @@ -43,9 +44,12 @@ then fi export AUTOJUMP_HOME=${HOME} -AUTOJUMP='{ [[ "$AUTOJUMP_HOME" == "$HOME" ]] && (autojump -a "$(pwd -P)"&)>/dev/null 2>>${AUTOJUMP_DATA_DIR}/.autojump_errors;} 2>/dev/null' -if [[ ! $PROMPT_COMMAND =~ autojump ]]; then - export PROMPT_COMMAND="$AUTOJUMP ; ${PROMPT_COMMAND:-:}" -fi +AUTOJUMP='{ [[ "$AUTOJUMP_HOME" == "$HOME" ]] && (autojump -a "$(pwd -P)"&)>/dev/null 2>>"${AUTOJUMP_DATA_DIR}/.autojump_errors";} 2>/dev/null' + +case $PROMPT_COMMAND in + *autojump*) ;; + *) export PROMPT_COMMAND="$AUTOJUMP ; ${PROMPT_COMMAND:-:}";; +esac + 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";else false; fi } +function j { new_path="$(autojump --bash $@)";if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; cd "$new_path";else false; fi } diff --git a/install.sh b/install.sh index 58e0644..89db3ae 100755 --- a/install.sh +++ b/install.sh @@ -16,7 +16,7 @@ #along with autojump. If not, see . function show_help { - echo "sudo ./install.sh [--prefix /usr/local]" + echo " ./install.sh [--prefix /usr/local]" } # Default install directory. @@ -41,17 +41,17 @@ done echo "Installing to ${prefix} ..." # INSTALL AUTOJUMP -sudo mkdir -p ${prefix}/share/autojump/ -sudo mkdir -p ${prefix}/bin/ -sudo mkdir -p ${prefix}/share/man/man1/ -sudo cp icon.png ${prefix}/share/autojump/ -sudo cp jumpapplet ${prefix}/bin/ -sudo cp autojump ${prefix}/bin/ -sudo cp autojump.1 ${prefix}/share/man/man1/ + mkdir -p ${prefix}/share/autojump/ + mkdir -p ${prefix}/bin/ + mkdir -p ${prefix}/share/man/man1/ + cp icon.png ${prefix}/share/autojump/ + cp jumpapplet ${prefix}/bin/ + cp autojump ${prefix}/bin/ + cp autojump.1 ${prefix}/share/man/man1/ if [ -d "/etc/profile.d" ]; then - sudo cp autojump.bash /etc/profile.d/ - sudo cp autojump.sh /etc/profile.d/ + cp autojump.bash /etc/profile.d/ + cp autojump.sh /etc/profile.d/ # Make sure that the code we just copied has been sourced. # check if .bashrc has sourced /etc/profile or /etc/profile.d/autojump.bash From d9a423370a72bb8aae640e4c048a99232c2b8351 Mon Sep 17 00:00:00 2001 From: xiaonaitong Date: Thu, 15 Sep 2011 16:05:51 +0800 Subject: [PATCH 2/8] redo previlege check except in windows --- autojump | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/autojump b/autojump index 114dd61..98816fc 100755 --- a/autojump +++ b/autojump @@ -55,24 +55,25 @@ def save(path_dict, dic_file): a backup file.""" # If the dic_file exists, check that it belongs to us # Otherwise, fail quietly - temp = NamedTemporaryFile(dir=CONFIG_DIR, delete=False) - pickle.dump(path_dict, temp, 2) - temp.flush() - os.fsync(temp) - temp.close() - #cf. http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/ - #os.rename(temp.name, dic_file) - import shutil - shutil.copy(temp.name, dic_file) - try: #backup file - import time - if (not os.path.exists(dic_file+".bak") or - time.time()-os.path.getmtime(dic_file+".bak")>86400): - import shutil - shutil.copy(dic_file, dic_file+".bak") - except OSError as ex: - print("Error while creating backup autojump file. (%s)" % - ex, file=stderr) + if (not os.path.exists(dic_file)) or os.name == 'nt' or os.getuid() == os.stat(dic_file)[4]: + temp = NamedTemporaryFile(dir=CONFIG_DIR, delete=False) + pickle.dump(path_dict, temp, 2) + temp.flush() + os.fsync(temp) + temp.close() + #cf. http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/ + #os.rename(temp.name, dic_file) + import shutil + shutil.copy(temp.name, dic_file) + try: #backup file + import time + if (not os.path.exists(dic_file+".bak") or + time.time()-os.path.getmtime(dic_file+".bak")>86400): + import shutil + shutil.copy(dic_file, dic_file+".bak") + except OSError as ex: + print("Error while creating backup autojump file. (%s)" % + ex, file=stderr) def forget(path_dict, dic_file): """Gradually forget about directories. Only call From b39c84ec8617c0333c400ecdd02aab6420fb43e1 Mon Sep 17 00:00:00 2001 From: xiaonaitong Date: Tue, 20 Sep 2011 09:46:09 +0800 Subject: [PATCH 3/8] sudo is needed in non-windows system --- install.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index 89db3ae..69e7a6c 100755 --- a/install.sh +++ b/install.sh @@ -41,13 +41,19 @@ done echo "Installing to ${prefix} ..." # INSTALL AUTOJUMP - mkdir -p ${prefix}/share/autojump/ - mkdir -p ${prefix}/bin/ - mkdir -p ${prefix}/share/man/man1/ - cp icon.png ${prefix}/share/autojump/ - cp jumpapplet ${prefix}/bin/ - cp autojump ${prefix}/bin/ - cp autojump.1 ${prefix}/share/man/man1/ +SUDO="sudo" +case "${OSTYPE}" in + *cygwin*|*msys*) + SUDO="";; + *);; +esac +$SUDO mkdir -p ${prefix}/share/autojump/ +$SUDO mkdir -p ${prefix}/bin/ +$SUDO mkdir -p ${prefix}/share/man/man1/ +$SUDO cp icon.png ${prefix}/share/autojump/ +$SUDO cp jumpapplet ${prefix}/bin/ +$SUDO cp autojump ${prefix}/bin/ +$SUDO cp autojump.1 ${prefix}/share/man/man1/ if [ -d "/etc/profile.d" ]; then cp autojump.bash /etc/profile.d/ From b318e11a6a53770212b17b39a139b25c5fbdc4d1 Mon Sep 17 00:00:00 2001 From: xiaonaitong Date: Tue, 20 Sep 2011 18:45:42 +0800 Subject: [PATCH 4/8] don't use --bash option in function j --- autojump.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autojump.bash b/autojump.bash index 59d0cb9..8b4020c 100644 --- a/autojump.bash +++ b/autojump.bash @@ -52,4 +52,4 @@ case $PROMPT_COMMAND in esac alias jumpstat="autojump --stat" -function j { new_path="$(autojump --bash $@)";if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; cd "$new_path";else false; fi } +function j { new_path="$(autojump $@)";if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; cd "$new_path";else false; fi } From 07e57679528506fc63276b541493618facafebe6 Mon Sep 17 00:00:00 2001 From: xiaonaitong Date: Tue, 20 Sep 2011 06:53:31 -0600 Subject: [PATCH 5/8] missing $SUDO when copy files to /etc/profile.d --- install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 69e7a6c..2b7d272 100755 --- a/install.sh +++ b/install.sh @@ -16,7 +16,7 @@ #along with autojump. If not, see . function show_help { - echo " ./install.sh [--prefix /usr/local]" + echo "sudo ./install.sh [--prefix /usr/local]" } # Default install directory. @@ -56,8 +56,8 @@ $SUDO cp autojump ${prefix}/bin/ $SUDO cp autojump.1 ${prefix}/share/man/man1/ if [ -d "/etc/profile.d" ]; then - cp autojump.bash /etc/profile.d/ - cp autojump.sh /etc/profile.d/ + $SUDO cp autojump.bash /etc/profile.d/ + $SUDO cp autojump.sh /etc/profile.d/ # Make sure that the code we just copied has been sourced. # check if .bashrc has sourced /etc/profile or /etc/profile.d/autojump.bash From d1a38d150e60ead1aa23dcde5f4c5be480aca44c Mon Sep 17 00:00:00 2001 From: xiaonaitong Date: Wed, 21 Sep 2011 10:26:49 +0800 Subject: [PATCH 6/8] don't need temp file --- autojump | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autojump b/autojump index 093e06b..5af1c15 100755 --- a/autojump +++ b/autojump @@ -88,7 +88,7 @@ def save(path_dict, dic_file): temp.close() #cf. http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/ import shutil - shutil.copy(temp.name, dic_file) + shutil.move(temp.name, dic_file) try: #backup file import time if (not os.path.exists(dic_file+".bak") or From e5e0001dadacf8927845456cc9a58ed50b8b776c Mon Sep 17 00:00:00 2001 From: xiaonaitong Date: Wed, 21 Sep 2011 18:34:17 +0800 Subject: [PATCH 7/8] fix completion error when path contain spaces add comment to explain that there is no need to check previlege in windows --- autojump | 2 +- autojump.bash | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/autojump b/autojump index 5af1c15..606f616 100755 --- a/autojump +++ b/autojump @@ -76,7 +76,7 @@ def unico(text): def save(path_dict, dic_file): """Save the database in an atomic way, and preserve a backup file.""" - # If the dic_file exists, check that it belongs to us + # If the dic_file exists and os is not windows, check that it belongs to us # Otherwise, fail quietly if (not os.path.exists(dic_file)) or os.name == 'nt' or os.getuid() == os.stat(dic_file)[4]: temp = NamedTemporaryFile(dir=CONFIG_DIR, delete=False) diff --git a/autojump.bash b/autojump.bash index 8b4020c..62e5c2f 100644 --- a/autojump.bash +++ b/autojump.bash @@ -20,10 +20,12 @@ _autojump() local cur cur=${COMP_WORDS[*]:1} comps=$(autojump --bash --completion $cur) - for i in $comps + while read i do COMPREPLY=("${COMPREPLY[@]}" "${i}") - done + done < Date: Wed, 21 Sep 2011 19:04:50 +0800 Subject: [PATCH 8/8] remove sudo in install.sh --- install.sh | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/install.sh b/install.sh index 2b7d272..d8506e4 100755 --- a/install.sh +++ b/install.sh @@ -41,23 +41,17 @@ done echo "Installing to ${prefix} ..." # INSTALL AUTOJUMP -SUDO="sudo" -case "${OSTYPE}" in - *cygwin*|*msys*) - SUDO="";; - *);; -esac -$SUDO mkdir -p ${prefix}/share/autojump/ -$SUDO mkdir -p ${prefix}/bin/ -$SUDO mkdir -p ${prefix}/share/man/man1/ -$SUDO cp icon.png ${prefix}/share/autojump/ -$SUDO cp jumpapplet ${prefix}/bin/ -$SUDO cp autojump ${prefix}/bin/ -$SUDO cp autojump.1 ${prefix}/share/man/man1/ +mkdir -p ${prefix}/share/autojump/ +mkdir -p ${prefix}/bin/ +mkdir -p ${prefix}/share/man/man1/ +cp icon.png ${prefix}/share/autojump/ +cp jumpapplet ${prefix}/bin/ +cp autojump ${prefix}/bin/ +cp autojump.1 ${prefix}/share/man/man1/ if [ -d "/etc/profile.d" ]; then - $SUDO cp autojump.bash /etc/profile.d/ - $SUDO cp autojump.sh /etc/profile.d/ + cp autojump.bash /etc/profile.d/ + cp autojump.sh /etc/profile.d/ # Make sure that the code we just copied has been sourced. # check if .bashrc has sourced /etc/profile or /etc/profile.d/autojump.bash