diff --git a/install.sh b/install.sh index 69bce33..9683ca4 100755 --- a/install.sh +++ b/install.sh @@ -71,27 +71,28 @@ _setup_terminal_shell() { _mappings_file="${_CONFIG_PATH}/lua/mappings.lua" # only ask for shellname if running in terminal if [ -t 1 ]; then - printf "%s\n: " "Which shell do you want to use ? [ Enter nothing for current shell ( $_CURRENT_SHELL ) ]" - read -r shellname + 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 fi - shellname="${shellname:-${_CURRENT_SHELL}}" - printf "%s\n" "$shellname" - # don't try to do any changes if given shellname is same as bash - if ! [ bash = "$shellname" ]; then + # 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") # Reference: https://stackoverflow.com/a/4247319 - if "${_SED}" -i'.bak' -e "s/bash/$shellname/g" "${_mappings_file}"; then - printf "\n%s\n" "=> Shell changed to $shellname on nvim successfully!" + # \( & \) 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!" else - printf "\n%s\n" "Cannot edit with sed, edit ${_mappings_file} manually to replace bash with $shellname." + 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 - else - printf "\n%s\n" "=> Shell changed to $shellname on nvim successfully!" fi + printf "%s\n\n" "=> Neovim shell will be ${shellpath:-${_CURRENT_SHELL}}" return 0 } - _setup_arguments() { # default variables to be used _CONFIG_PATH="${HOME}/.config/nvim"