Update cast.sh
Amended shell check to make it cross platform compatible.
This commit is contained in:
38
cast.sh
38
cast.sh
@@ -145,9 +145,27 @@ install_plugins() {
|
|||||||
|
|
||||||
# 🐚 Ask to set Fish as default shell (only if not already)
|
# 🐚 Ask to set Fish as default shell (only if not already)
|
||||||
set_fish_default() {
|
set_fish_default() {
|
||||||
local fish_path current_shell
|
local fish_path current_shell confirm
|
||||||
|
|
||||||
fish_path="$(command -v fish)"
|
fish_path="$(command -v fish)"
|
||||||
current_shell="$(getent passwd "$USER" | cut -d: -f7)"
|
|
||||||
|
if [[ -z "$fish_path" ]]; then
|
||||||
|
echo "✗ Fish is not installed or not in PATH"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Detect the user's configured login shell in a cross-platform way
|
||||||
|
if command -v getent >/dev/null 2>&1; then
|
||||||
|
# Linux / glibc systems
|
||||||
|
current_shell="$(getent passwd "$USER" | cut -d: -f7)"
|
||||||
|
elif command -v dscl >/dev/null 2>&1; then
|
||||||
|
# macOS
|
||||||
|
current_shell="$(dscl . -read "/Users/$USER" UserShell 2>/dev/null | awk '{print $2}')"
|
||||||
|
else
|
||||||
|
# Fallback: try /etc/passwd, then SHELL env var
|
||||||
|
current_shell="$(awk -F: -v user="$USER" '$1 == user {print $7}' /etc/passwd 2>/dev/null)"
|
||||||
|
[[ -z "$current_shell" ]] && current_shell="$SHELL"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$current_shell" == "$fish_path" ]]; then
|
if [[ "$current_shell" == "$fish_path" ]]; then
|
||||||
echo "✓ Fish is already your default shell"
|
echo "✓ Fish is already your default shell"
|
||||||
@@ -156,11 +174,19 @@ set_fish_default() {
|
|||||||
|
|
||||||
read -rp "Set Fish as your default shell? (y/N): " confirm
|
read -rp "Set Fish as your default shell? (y/N): " confirm
|
||||||
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
||||||
if ! grep -q "^$fish_path$" /etc/shells; then
|
# Only try to add to /etc/shells if that file exists
|
||||||
echo "$fish_path" | sudo tee -a /etc/shells >/dev/null
|
if [[ -f /etc/shells ]]; then
|
||||||
|
if ! grep -qx "$fish_path" /etc/shells; then
|
||||||
|
echo "$fish_path" | sudo tee -a /etc/shells >/dev/null
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if chsh -s "$fish_path"; then
|
||||||
|
echo "✓ Fish set as default shell (applies to new sessions)"
|
||||||
|
else
|
||||||
|
echo "✗ Failed to set Fish as default shell"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
chsh -s "$fish_path"
|
|
||||||
echo "✓ Fish set as default shell (applies to new sessions)"
|
|
||||||
else
|
else
|
||||||
echo "✓ Keeping current default shell"
|
echo "✓ Keeping current default shell"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user