mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 11:14:08 +00:00
chore(bin): fish support shared.sh and dfm
This commit is contained in:
@@ -17,13 +17,53 @@ DEBUG="${DEBUG:-0}"
|
||||
# Enable debugging with DEBUG=1
|
||||
[ "${DEBUG:-0}" -eq 1 ] && set -x
|
||||
|
||||
# Detect the current shell
|
||||
CURRENT_SHELL=$(ps -p $$ -ocomm= | awk -F/ '{print $NF}')
|
||||
|
||||
# Function to prepend a path to PATH based on the shell
|
||||
x-path-prepend()
|
||||
{
|
||||
local dir=$1
|
||||
case "$CURRENT_SHELL" in
|
||||
fish)
|
||||
set -U fish_user_paths "$dir" $fish_user_paths
|
||||
;;
|
||||
sh | bash | zsh)
|
||||
PATH="$dir:$PATH"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported shell: $CURRENT_SHELL"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to set environment variables based on the shell
|
||||
x-set-env()
|
||||
{
|
||||
local var=$1
|
||||
local value=$2
|
||||
case "$CURRENT_SHELL" in
|
||||
fish)
|
||||
set -x "$var" "$value"
|
||||
;;
|
||||
sh | bash | zsh)
|
||||
export "$var=$value"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported shell: $CURRENT_SHELL"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Explicitly set XDG folders, if not already set
|
||||
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
[ -z "$XDG_CONFIG_HOME" ] && export XDG_CONFIG_HOME="$HOME/.config"
|
||||
[ -z "$XDG_DATA_HOME" ] && export XDG_DATA_HOME="$HOME/.local/share"
|
||||
[ -z "$XDG_CACHE_HOME" ] && export XDG_CACHE_HOME="$HOME/.cache"
|
||||
[ -z "$XDG_STATE_HOME" ] && export XDG_STATE_HOME="$HOME/.local/state"
|
||||
[ -z "$XDG_BIN_HOME" ] && export XDG_BIN_HOME="$HOME/.local/bin"
|
||||
x-set-env XDG_CONFIG_HOME "$HOME/.config"
|
||||
x-set-env XDG_DATA_HOME "$HOME/.local/share"
|
||||
x-set-env XDG_CACHE_HOME "$HOME/.cache"
|
||||
x-set-env XDG_STATE_HOME "$HOME/.local/state"
|
||||
x-set-env XDG_BIN_HOME "$HOME/.local/bin"
|
||||
|
||||
# Paths
|
||||
x-path-prepend "/usr/local/bin"
|
||||
|
||||
@@ -15,9 +15,35 @@
|
||||
|
||||
SCRIPT=$(basename "$0")
|
||||
|
||||
# Loads configs for better installation experience
|
||||
source "$DOTFILES/config/shared.sh"
|
||||
source "${DOTFILES}/local/bin/msgr"
|
||||
# Detect the current shell
|
||||
CURRENT_SHELL=$(ps -p $$ -ocomm= | awk -F/ '{print $NF}')
|
||||
|
||||
# Function to source files based on the shell
|
||||
source_file()
|
||||
{
|
||||
local file=$1
|
||||
case "$CURRENT_SHELL" in
|
||||
fish)
|
||||
if [[ -f "$file.fish" ]]; then
|
||||
source "$file.fish"
|
||||
else
|
||||
echo "Fish shell file not found: $file.fish"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
sh | bash | zsh)
|
||||
source "$file"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported shell: $CURRENT_SHELL"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Modify the source commands to use the new function
|
||||
source_file "$DOTFILES/config/shared.sh"
|
||||
source_file "${DOTFILES}/local/bin/msgr"
|
||||
|
||||
# Menu builder
|
||||
menu_builder()
|
||||
@@ -267,7 +293,7 @@ section_helpers()
|
||||
{
|
||||
USAGE_PREFIX="$SCRIPT helpers <command>"
|
||||
MENU=(
|
||||
"aliases:<shell> (bash, zsh) Show aliases"
|
||||
"aliases:<shell> (bash, zsh, fish) Show aliases"
|
||||
"colors:Show colors"
|
||||
"env:Show environment variables"
|
||||
"functions:Show functions"
|
||||
@@ -297,8 +323,11 @@ section_helpers()
|
||||
"bash")
|
||||
bash -ixc : 2>&1 | grep -E '> alias' | sed "s|$HOME|~|" | grep -v "(eval)"
|
||||
;;
|
||||
"fish")
|
||||
fish -ic "alias" | sed "s|$HOME|~|"
|
||||
;;
|
||||
*)
|
||||
echo "$SCRIPT helpers aliases <shell> (bash, zsh)"
|
||||
echo "$SCRIPT helpers aliases <shell> (bash, zsh, fish)"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user