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