dotfiles/.config/shell/profile

133 lines
3.9 KiB
Text
Raw Normal View History

2024-04-12 18:31:25 +02:00
#!/bin/sh
2022-05-27 21:07:07 +02:00
# Default programs:
export BROWSER=firefox
export EDITOR=vim
export FILE=ranger
export IMAGES=feh
export PAGER=less
2023-08-29 13:53:53 +02:00
export TERMINAL=kitty
2022-05-27 21:07:07 +02:00
export VISUAL=code
2023-09-15 14:19:58 +02:00
# Misc vars
export CHROME_EXECUTABLE=chromium # For Flutter
2024-04-12 16:37:01 +02:00
# Set XDG directories:
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
2022-05-27 21:07:07 +02:00
# Clean home:
2024-04-12 16:37:01 +02:00
export ANDROID_HOME="$XDG_DATA_HOME/Android/Sdk"
export CARGO_HOME="$XDG_DATA_HOME/cargo"
export KREW_ROOT="$XDG_DATA_HOME/krew"
export FLUTTER_HOME="$XDG_DATA_HOME/flutter"
export GOPATH="$XDG_DATA_HOME/go"
export HISTFILE="$XDG_DATA_HOME/history"
export XINITRC="$XDG_CONFIG_HOME/x11/xinitrc"
export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
export NVM_DIR="$XDG_CONFIG_HOME/nvm"
export NUGET_PACKAGES="$XDG_DATA_HOME/nuget"
2022-05-27 21:07:07 +02:00
# Color man pages:
2024-04-12 18:31:25 +02:00
export LESS='-r'
export LESS_TERMCAP_mb
export LESS_TERMCAP_md
export LESS_TERMCAP_me
export LESS_TERMCAP_se
export LESS_TERMCAP_so
export LESS_TERMCAP_ue
export LESS_TERMCAP_us
LESS_TERMCAP_mb="$(printf '\033[01;32m')"
LESS_TERMCAP_md="$(printf '\033[01;32m')"
LESS_TERMCAP_me="$(printf '\033[0m')"
LESS_TERMCAP_se="$(printf '\033[0m')"
LESS_TERMCAP_so="$(printf '\033[01;47;34m')"
LESS_TERMCAP_ue="$(printf '\033[0m')"
LESS_TERMCAP_us="$(printf '\033[01;36m')"
2022-05-27 21:07:07 +02:00
# Other program settings:
export DISPLAY_DPI=96
2024-04-12 18:31:25 +02:00
_tr="$(which tr 2>/dev/null || echo /usr/bin/tr)"
_sed="$(which sed 2>/dev/null || echo /usr/bin/sed)"
2022-12-15 16:01:39 +01:00
2024-04-12 18:31:25 +02:00
# Trims the specified leading and trailing characters from the string
trim() {
string="${1:?Missing string}"
char="${2:?Missing trim character}"
echo "$string" | $_sed "s/^$char*//; s/$char*$//"
2022-12-15 16:01:39 +01:00
}
2024-04-12 18:31:25 +02:00
rm_env_path_entry() {
src_entries="${1:?Missing source entries}"
del_entry="${2:?Missing entry to delete}"
new_entries=""
2022-12-15 16:01:39 +01:00
2024-04-12 18:31:25 +02:00
echo "$src_entries" | $_tr ':' '\n' | while read -r entry; do
if [ "$entry" != "$del_entry" ]; then
new_entries="$new_entries:$entry"
fi
2022-12-15 16:01:39 +01:00
done
2024-04-12 18:31:25 +02:00
trim "$new_entries" ":"
2022-12-15 16:01:39 +01:00
}
2024-04-12 18:31:25 +02:00
modify_env_path() {
mode="${1:?Missing mode}"
entries="${2:?Missing entries}"
change="${3:?Missing change}"
entries="$(trim "$entries" ":")"
case "$mode" in
prepend)
temp_entries="" # Will hold the new entries in the correct order
echo "$change" | $_tr ':' '\n' | while read -r entry; do
[ -z "$entry" ] && continue # Skip empty entries
[ -d "$entry" ] || continue # Skip non-existent directories
temp_entries="$temp_entries:$entry"
done
# Merge the added entries to the existing entries
# Trim the leading colon and append the new entries
entries="${temp_entries#:}:$entries"
;;
append)
echo "$change" | $_tr ':' '\n' | while read -r entry; do
[ -z "$entry" ] && continue # Skip empty entries
[ -d "$entry" ] || continue # Skip non-existent directories
entries="$entries:$entry"
done
;;
delete)
echo "$change" | $_tr ':' '\n' | while read -r entry; do
[ -z "$entry" ] && continue # Skip empty entries
entries=$(rm_env_path_entry "$entries" "$entry")
done
;;
*)
echo "Invalid mode: $mode (choose 'append', 'prepend', 'delete')" >&2
return 1
;;
esac
trim "$entries" ":"
2022-12-15 16:01:39 +01:00
}
2024-04-12 18:31:25 +02:00
prepend_paths="$HOME/.local/bin:$HOME/.cargo/bin:$FLUTTER_HOME/bin:$GOPATH/bin:$KREW_ROOT/bin"
2022-05-27 21:07:07 +02:00
2024-04-11 12:15:19 +02:00
HOMEBREW_PREFIX="$XDG_DATA_HOME/homebrew"
if [ -x "$HOMEBREW_PREFIX/bin/brew" ]; then
eval "$("$HOMEBREW_PREFIX/bin/brew" shellenv)"
2024-04-12 18:31:25 +02:00
prepend_paths="$HOMEBREW_PREFIX/bin:$HOMEBREW_PREFIX/sbin:$prepend_paths"
2024-04-11 12:15:19 +02:00
fi
2022-12-15 16:01:39 +01:00
2024-04-12 18:31:25 +02:00
PATH="$(modify_env_path delete "$PATH" "$prepend_paths")"
PATH="$(modify_env_path prepend "$PATH" "$prepend_paths")"
2022-05-28 23:00:55 +02:00
# Add the profile-extras file yourself if you wish to override anything:
2024-04-12 16:37:01 +02:00
PROFILE_EXTRAS="$XDG_CONFIG_HOME/shell/profile-extras"
2024-04-12 18:31:25 +02:00
[ -f "$PROFILE_EXTRAS" ] && . "$PROFILE_EXTRAS" || true