1
0
mirror of https://github.com/wting/autojump synced 2024-09-28 22:10:45 +00:00

fix install.sh test construct, simplified install.sh, minor formatting changes

This commit is contained in:
William Ting 2012-02-07 16:21:37 -10:00
parent 149863c322
commit 770b80bfe4
2 changed files with 24 additions and 44 deletions

View File

@ -21,7 +21,7 @@ function show_help {
# Default install directory. # Default install directory.
prefix=/usr prefix=/usr
local=0 local=
user=${SUDO_USER:-${USER}} user=${SUDO_USER:-${USER}}
OS=`uname` OS=`uname`
@ -41,14 +41,13 @@ while true; do
exit 0 exit 0
;; ;;
-l|--local) -l|--local)
local=1 local=true
prefix=~/.autojump prefix=~/.autojump
shift shift
;; ;;
-p|--prefix) -p|--prefix)
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
prefix=$2; shift 2 prefix=$2; shift 2
profile_d=$prefix/etc/autojump
else else
die "--prefix or -p require an argument" die "--prefix or -p require an argument"
fi fi
@ -73,7 +72,7 @@ if [[ ${UID} != 0 ]] && [ ! ${local} ]; then
exit 1 exit 1
fi fi
echo "Installing main files to ${prefix} ..." echo -e "Installing files to ${prefix} ...\n"
# add git revision to autojump # add git revision to autojump
./git-version.sh ./git-version.sh
@ -92,44 +91,17 @@ if [ ! ${local} ]; then
cp -v autojump.bash /etc/profile.d/ cp -v autojump.bash /etc/profile.d/
cp -v autojump.sh /etc/profile.d/ cp -v autojump.sh /etc/profile.d/
# Make sure that the code we just copied has been sourced. echo
# check if .bashrc has sourced /etc/profile or /etc/profile.d/autojump.bash echo "Add the following lines to your ~/.bashrc:"
if [ `grep -c "^[[:space:]]*\(source\|\.\) /etc/profile\(\.d/autojump\.bash\)[[:space:]]*$" ${bashrc_file}` -eq 0 ]; then echo
echo "Your .bashrc doesn't seem to source /etc/profile or $profile_d/autojump.bash" echo -e "\tsource ${prefix}/etc/profile.d/autojump.bash"
echo "Adding the /etc/profile.d/autojump.bash to your .bashrc"
echo "" >> ${bashrc_file}
echo "# Added by autojump install.sh" >> ${bashrc_file}
echo "source /etc/profile.d/autojump.bash" >> ${bashrc_file}
fi
echo "Done!"
echo echo
echo "You need to source your ~/.bashrc (source ~/.bashrc) before you can start using autojump." echo "You need to source your ~/.bashrc (source ~/.bashrc) before you can start using autojump."
echo
echo "To remove autojump, delete the ${prefix} directory and relevant lines from ~/.bashrc."
echo
else else
echo "Your distribution does not have a $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]" echo "Your distribution does not have a '/etc/profile.d/' directory, please create it manually or use the local install option."
read ans
if [ ${#ans} -gt 0 ]; then
if [ $ans = "y" -o $ans = "Y" -o $ans = "yes" -o $ans = "Yes" ]; then
# Answered yes. Go ahead and add the autojump code
echo "" >> ${bashrc_file}
echo "#autojump" >> ${bashrc_file}
cat autojump.bash | grep -v "^#" >> ${bashrc_file}
# Since OSX uses .bash_profile, we need to make sure that .bashrc is properly sourced.
# Makes the assumption that if they have a line: source ~/.bashrc or . ~/.bashrc, that
# .bashrc has been properly sourced and you don't need to add it.
if [ $OS == 'Darwin' -a x`grep -c "^[[:space:]]*\(source\|\.\) ~/\.bashrc[[:space:]]*$" ~/.bash_profile` == x0 ]; then
echo "You are using OSX and your .bash_profile doesn't seem to be sourcing .bashrc"
echo "Adding source ~/.bashrc to your bashrc"
echo -e "\n# Get the aliases and functions" >> ~/.bash_profile
echo -e "if [ -f ${bashrc_file} ]; then\n . ${bashrc_file}\nfi" >> ~/.bash_profile
fi
echo "You need to source your ~/.bashrc (source ~/.bashrc) before you can start using autojump."
else
echo "Then you need to put autojump.sh, or the code from it, somewhere where it will get read. Good luck!"
fi
else
echo "Then you need to put autojump.sh, or the code from it, somewhere where it will get read. Good luck!"
fi
fi fi
else else
mkdir -p ${prefix}/etc/profile.d/ mkdir -p ${prefix}/etc/profile.d/
@ -144,5 +116,5 @@ else
echo "You need to source your ~/.bashrc (source ~/.bashrc) before you can start using autojump." echo "You need to source your ~/.bashrc (source ~/.bashrc) before you can start using autojump."
echo echo
echo "To remove autojump, delete the ${prefix} directory and relevant lines from ~/.bashrc." echo "To remove autojump, delete the ${prefix} directory and relevant lines from ~/.bashrc."
echo
fi fi

View File

@ -58,18 +58,26 @@ if [ -d "${prefix}/share/autojump/" ]; then
sudo rm -v ${prefix}/bin/jumpapplet sudo rm -v ${prefix}/bin/jumpapplet
sudo rm -v ${prefix}/bin/autojump sudo rm -v ${prefix}/bin/autojump
sudo rm -v ${prefix}/share/man/man1/autojump.1 sudo rm -v ${prefix}/share/man/man1/autojump.1
sudo rm -v /etc/profile.d/autojump.zsh sudo rm -v /etc/profile.d/autojump.bash
sudo rm -v /etc/profile.d/autojump.sh sudo rm -v /etc/profile.d/autojump.sh
echo -e "\nPlease remove the line from ${bashrc_file} :\n" echo
echo "Please remove the line from ${bashrc_file} :"
echo
echo -e "\tsource /etc/profile.d/autojump.bash" echo -e "\tsource /etc/profile.d/autojump.bash"
echo
fi fi
# local installations # local installations
if [ -d ~/.autojump/ ]; then if [ -d ~/.autojump/ ]; then
echo -e "\nUninstalling from ~/.autojump/ ...\n" echo
echo "Uninstalling from ~/.autojump/ ..."
echo
rm -rv ~/.autojump/ rm -rv ~/.autojump/
echo -e "\nPlease remove the line from ${bashrc_file} :\n" echo
echo "Please remove the line from ${bashrc_file} :"
echo
echo -e "\tsource ~/.autojump/profile.d/autojump.bash" echo -e "\tsource ~/.autojump/profile.d/autojump.bash"
echo
fi fi