install.sh: Use chsh instead of grep /etc/shells
This commit is contained in:
parent
766d52db12
commit
3fc587b54d
25
install.sh
25
install.sh
@ -21,7 +21,7 @@ _check_install_dependencies() {
|
||||
printf "%s\n" "Error: Install ${1} before proceeding."
|
||||
exit 1
|
||||
}
|
||||
_GIT="$(command -v git)" || _error_dependencies git
|
||||
command -v git 1>/dev/null || _error_dependencies git
|
||||
_SED="$(command -v sed)" || _error_dependencies sed
|
||||
return 0
|
||||
}
|
||||
@ -71,26 +71,29 @@ _setup_terminal_shell() {
|
||||
_mappings_file="${_CONFIG_PATH}/lua/mappings.lua"
|
||||
# only ask for shellname if running in terminal
|
||||
if [ -t 1 ]; then
|
||||
printf "\n%s\n" "Which shell do you want to use? (Eg. 2)"
|
||||
printf "\t%s\n" "[ Enter nothing for current shell ( $_CURRENT_SHELL ) ]"
|
||||
grep '^/bin/' '/etc/shells' | nl
|
||||
read -r shellNUM
|
||||
if chsh -l 2>/dev/null 1>&2; then
|
||||
printf "\nAvailable Shells:\n"
|
||||
chsh -l | nl
|
||||
printf "\n%s\n" "Which shell do you want to use? (Eg. 2)"
|
||||
printf "\t%s\n" "[ Enter nothing for current shell ( $_CURRENT_SHELL ) ]"
|
||||
read -r shellnum
|
||||
[ "${shellnum}" -gt 0 ] 2>/dev/null && _SHELLPATH="$(chsh -l | sed -n "$shellnum p")"
|
||||
fi
|
||||
fi
|
||||
|
||||
# don't try to do any changes user wants their default shell in nvim
|
||||
if [ ! -z "$shellNUM" ]; then
|
||||
shellpath=$(grep '^/bin/' '/etc/shells' | sed -n "$shellNUM p")
|
||||
if [ -n "$_SHELLPATH" ]; then
|
||||
# Reference: https://stackoverflow.com/a/4247319
|
||||
# \( & \) will use regex brackets (for later reference with \1)
|
||||
# ( & ) will match text brackets
|
||||
if "${_SED}" --posix -i'.bak' -e "s=^\(map(.* \+*terminal\) \(.*)\)=\1$shellpath \2=g" "${_mappings_file}"; then
|
||||
printf "%s\n" "=> Neovim shell changed to $shellpath successfully!"
|
||||
if "${_SED}" --posix -i'.bak' -e "s=^\(map(.* \+*terminal\) \(.*)\)=\1$_SHELLPATH \2=g" "${_mappings_file}"; then
|
||||
printf "%s\n" "=> Neovim shell changed to $_SHELLPATH successfully!"
|
||||
else
|
||||
printf "%s\n" "Cannot edit with sed, edit ${_mappings_file} manually to replace bash with $shellpath."
|
||||
printf "%s\n" "Cannot edit with sed, edit ${_mappings_file} manually to replace bash with $_SHELLPATH."
|
||||
fi
|
||||
rm -f "${_mappings_file}".bak # delete backup file created by sed
|
||||
fi
|
||||
printf "%s\n\n" "=> Neovim shell will be ${shellpath:-${_CURRENT_SHELL}}"
|
||||
printf "%s\n" "=> Neovim shell will be ${_SHELLPATH:-${_CURRENT_SHELL}}"
|
||||
return 0
|
||||
}
|
||||
_setup_arguments() {
|
||||
|
Loading…
Reference in New Issue
Block a user