mirror of
https://github.com/iridakos/goto.git
synced 2025-05-15 23:10:35 -07:00
40 lines
907 B
Bash
Executable File
40 lines
907 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
function _goto_install_error()
|
|
{
|
|
echo "$@" >&2
|
|
}
|
|
|
|
# sudo-check
|
|
if [ $EUID -ne 0 ]; then
|
|
_goto_install_error 'Please run this script in sudo mode or as root user'
|
|
exit
|
|
fi
|
|
|
|
GOTO_FILE_LOCATION='/usr/local/share/goto.bash'
|
|
RC=""
|
|
if [ -f ~/.bashrc ]; then
|
|
RC="$HOME/.bashrc"
|
|
elif [ -f ~/.cshrc ]; then
|
|
RC="$HOME/.cshrc"
|
|
elif [ -f ~/.kshrc ]; then
|
|
RC="$HOME/.kshrc"
|
|
elif [ -f ~/.zshrc ]; then
|
|
RC="$HOME/.zshrc"
|
|
fi
|
|
|
|
cp ./goto.bash "$GOTO_FILE_LOCATION"
|
|
|
|
if [ -n "$RC" ]; then
|
|
# Append source to RC startup file if not already there
|
|
if [ `grep -c "source $GOTO_FILE_LOCATION" "$RC"` == "0" ]; then
|
|
# Append source to RC file
|
|
echo -e "\n#Source goto\nsource $GOTO_FILE_LOCATION\n" >> "$RC"
|
|
fi
|
|
source "$GOTO_FILE_LOCATION"
|
|
else
|
|
_goto_install_error "Error sourcing goto in your startup file.."
|
|
_goto_install_error "E.g ~/.bashrc ~/.cshrc etc.."
|
|
fi
|
|
|