From f3d00f06715f3ae0eb4d905cfe3451a2fd6c9596 Mon Sep 17 00:00:00 2001 From: William Ting Date: Sun, 24 Apr 2011 18:54:55 -1000 Subject: [PATCH 1/2] combining cd && ls into j function --- autojump.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autojump.bash b/autojump.bash index e512640..f3811b6 100644 --- a/autojump.bash +++ b/autojump.bash @@ -45,6 +45,6 @@ fi 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="${PROMPT_COMMAND:-:} ; $AUTOJUMP" -fi +fi 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 $@)";if [ -n "$new_path" ]; then echo -e "\\033[31m${new_path}\\033[0m"; cd "$new_path" && ls;else false; fi } From 7add5c601ed58fbfc24d17c3c4c437da2742bd73 Mon Sep 17 00:00:00 2001 From: William Ting Date: Sat, 14 May 2011 00:09:02 -0500 Subject: [PATCH 2/2] modify install script to support local installs --- autojump.bash | 22 +++++-------------- install.sh | 58 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/autojump.bash b/autojump.bash index f3811b6..8e851d4 100644 --- a/autojump.bash +++ b/autojump.bash @@ -25,26 +25,14 @@ _autojump() done < <(autojump --bash --completion $cur) } complete -F _autojump j -#data_dir=${XDG_DATA_HOME:-$([ -e ~/.local/share ] && echo ~/.local/share || echo ~)} -data_dir=$([ -e ~/.local/share ] && echo ~/.local/share || echo ~) + export AUTOJUMP_HOME=${HOME} -if [[ "$data_dir" = "${HOME}" ]] -then - export AUTOJUMP_DATA_DIR=${data_dir} -else - export AUTOJUMP_DATA_DIR=${data_dir}/autojump -fi -if [ ! -e "${AUTOJUMP_DATA_DIR}" ] -then - mkdir "${AUTOJUMP_DATA_DIR}" - mv ~/.autojump_py "${AUTOJUMP_DATA_DIR}/autojump_py" 2>>/dev/null #migration - mv ~/.autojump_py.bak "${AUTOJUMP_DATA_DIR}/autojump_py.bak" 2>>/dev/null - mv ~/.autojump_errors "${AUTOJUMP_DATA_DIR}/autojump_errors" 2>>/dev/null -fi +export AUTOJUMP_DATA_DIR=${HOME}/.autojump 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="${PROMPT_COMMAND:-:} ; $AUTOJUMP" + export PROMPT_COMMAND="${PROMPT_COMMAND:-:} ; $AUTOJUMP" fi + 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" && ls;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 } diff --git a/install.sh b/install.sh index 169d5cf..3504f87 100755 --- a/install.sh +++ b/install.sh @@ -19,9 +19,6 @@ function show_help { echo "sudo ./install.sh [--prefix /usr/local]" } -# Default install directory. -prefix=/usr/local - # Command line parsing while true; do case "$1" in @@ -58,6 +55,21 @@ if [ ${uninstall} == 1 ]; then sudo rm /usr/share/man/man1/autojump.1 fi +all_users=0; +while true; do + read -p "Install for all users (requires root)? [Yn] " yn + case $yn in + [Yy]* ) all_users=1; break;; + [Nn]* ) all_users=0; break;; + * ) all_users=1; break;; + esac +done + +prefix=/usr/local +if [ ${all_users} == 0 ]; then + prefix=${HOME}/.autojump +fi + echo "Installing to ${prefix} ..." # INSTALL AUTOJUMP @@ -69,24 +81,42 @@ sudo cp jumpapplet ${prefix}/bin/ sudo cp autojump ${prefix}/bin/ sudo 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/ +if [ `uname` != "Darwin" ]; then + if [ ${all_users} == 1 ]; then + sudo mkdir -p /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 - if [ `grep -c "^[[:space:]]*\(source\|\.\) /etc/profile\(\.d/autojump\.bash\)[[:space:]]*$" ~/.bashrc` -eq 0 ]; then - echo "Your .bashrc doesn't seem to source /etc/profile or /etc/profile.d/autojump.bash" - echo "Adding the /etc/profile.d/autojump.bash to your .bashrc" - echo "" >> ~/.bashrc - echo "# Added by autojump install.sh" >> ~/.bashrc - echo "source /etc/profile.d/autojump.bash" >> ~/.bashrc + # Make sure that the code we just copied has been sourced. + # check if .bashrc has sourced /etc/profile or /etc/profile.d/autojump.bash + if [ `grep -c "^[[:space:]]*\(source\|\.\) /etc/profile\(\.d/autojump\.bash\)[[:space:]]*$" ~/.bashrc` -eq 0 ]; then + echo "Your .bashrc doesn't seem to source /etc/profile or /etc/profile.d/autojump.bash" + echo "Adding the /etc/profile.d/autojump.bash to your .bashrc" + echo "" >> ~/.bashrc + echo "# Added by autojump install.sh" >> ~/.bashrc + echo "source /etc/profile.d/autojump.bash" >> ~/.bashrc + fi + else + mkdir -p ${prefix}/etc/profile.d/ + cp autojump.bash ${prefix}/etc/profile.d/ + cp autojump.sh ${prefix}/etc/profile.d/ + + if [ `grep -c "^[[:space:]]*\(source\|\.\) ${prefix}/etc/profile\(\.d/autojump\.bash\)[[:space:]]*$" ~/.bashrc` -eq 0 ]; then + echo "Your .bashrc doesn't seem to source /etc/profile or /etc/profile.d/autojump.bash" + echo "Adding the /etc/profile.d/autojump.bash to your .bashrc" + echo "" >> ~/.bashrc + echo "# Added by autojump install.sh" >> ~/.bashrc + echo "source ${prefix}/etc/profile.d/autojump.bash" >> ~/.bashrc + fi fi + echo "Done!" echo echo "You need to source your ~/.bashrc (source ~/.bashrc) before you can start using autojump." + 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 ~/.bashrc 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