dotwryn/zsh/colors

131 lines
3.6 KiB
Plaintext
Raw Normal View History

2019-12-31 00:48:53 +00:00
#!/bin/zsh
2021-09-16 20:56:05 +00:00
#####################################################################
2019-12-31 00:48:53 +00:00
2021-09-17 04:42:41 +00:00
alias ls='ls --color=auto --group-directories-first'
2019-12-31 02:45:05 +00:00
2021-09-16 20:56:05 +00:00
#####################################################################
2019-12-31 00:48:53 +00:00
2021-09-21 17:00:31 +00:00
PS1__GET_DIRECTORY() {
local _DIRECTORY="%B%F{yellow}%6~"
local GIT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
[ $GIT_ROOT ] && {
local PROJECT_NAME=$(basename $GIT_ROOT)
2021-09-21 17:51:02 +00:00
[[ $PROJECT_NAME =~ ^code$ ]] && PROJECT_NAME=$(basename $(dirname $GIT_ROOT))
2021-09-21 17:00:31 +00:00
local RELATIVE_DIRECTORY=${${PWD#$GIT_ROOT}:1}
[[ ${#${RELATIVE_DIRECTORY//[^\/]}} -gt 3 ]] && RELATIVE_DIRECTORY='*/%4~'
_DIRECTORY="%B%F{green}$PROJECT_NAME%B%F{yellow}:$RELATIVE_DIRECTORY"
}
echo $_DIRECTORY
}
PS1__GET_GIT_BRANCH() {
local _GIT_BRANCH=$(\
git branch --no-color 2>/dev/null \
| sed "/^[^*]/d; s/* \(.*\)/ %B%F{cyan}$PS1_BRANCH_SYMBOL \1/" \
)
echo $_GIT_BRANCH
}
2021-09-16 20:56:05 +00:00
GENERATE_PS1() {
2021-09-21 17:00:31 +00:00
2021-09-16 21:06:49 +00:00
local _INDICATOR="%B%(?.%F{green}.%F{red}) $PS1_INDICATOR_SYMBOL"
local _USER="%B%F{magenta}$PS1_USER"
local _SEPARATOR="%b%F{red}$PS1_SEPARATOR"
2021-09-21 17:00:31 +00:00
local _DIRECTORY='$(PS1__GET_DIRECTORY)'
local _GIT_BRANCH='$(PS1__GET_GIT_BRANCH)'
2019-12-31 02:00:58 +00:00
2021-09-16 20:56:05 +00:00
local _PROMPT=$'\n'' %B%F{blue}%# %b%f'
2019-12-31 02:00:58 +00:00
2021-09-16 20:56:05 +00:00
echo "$_INDICATOR $_USER $_SEPARATOR $_DIRECTORY $_GIT_BRANCH $_PROMPT"
2019-12-31 02:45:05 +00:00
}
2019-12-31 02:00:58 +00:00
setopt PROMPT_SUBST
2021-09-16 21:06:49 +00:00
export PS1="$(GENERATE_PS1)"
2021-06-28 19:09:54 +00:00
source "$DOTWRYN/config/colorschemes/linux-console"
2021-06-28 19:09:54 +00:00
#####################################################################
2021-06-28 19:09:54 +00:00
FZF_THEME_PICK() {
echo "$(\
sed 's/\.conf//g; s/^./\U&/; s/-\(.\)/\U\1/g; s/^Default/& (use kitty theme)/' \
| fzf -i --height=50% --reverse --prompt 'select a theme : ' \
| sed 's/^./\L&/; s/[A-Z]/-\L&/g'
).conf"
}
GET_KITTY_THEMES() { ls "$DOTWRYN/config/colorschemes/kitty"; }
alias kitty-change-theme='KITTY_CHANGE_THEME default'
alias kitty-change-theme-alternate='KITTY_CHANGE_THEME alternate'
KITTY_CHANGE_THEME () {
local USAGE="usage : $0 target [theme]"
local TARGET="$1"
local TARGET_LINK
case $TARGET in
default ) TARGET_LINK="$DOTWRYN/config/kitty/theme.conf" ;;
alternate ) TARGET_LINK="$DOTWRYN/config/kitty/alternate.conf" ;;
* )
echo "error : target must be 'default' or 'alternate'\n$USAGE" >&2
return 1
;;
esac
local THEME="$2"
[ ! $THEME ] && {
THEME=$(GET_KITTY_THEMES | FZF_THEME_PICK)
[ ! $THEME ] && return 2
}
2021-09-21 17:00:31 +00:00
local COLORSCHEME="$DOTWRYN/config/colorschemes/kitty/$THEME"
[ ! -f $COLORSCHEME ] && { echo "no such theme ($THEME)"; return 2; }
rm -- $TARGET_LINK
ln -s $COLORSCHEME $TARGET_LINK && {
echo 'kitty-term theme changed successfully! (effective on new session)'
source "$DOTWRYN/config/colorschemes/linux-console"
}
2021-06-28 19:09:54 +00:00
}
_KITTY_CHANGE_THEME () { compadd $(GET_KITTY_THEMES); }
compdef _KITTY_CHANGE_THEME KITTY_CHANGE_THEME
2021-06-28 19:09:54 +00:00
2021-09-16 20:56:05 +00:00
#####################################################################
GET_TTY_THEMES() {
echo default
ls "$DOTWRYN/config/colorschemes/kitty"
}
alias tty-change-theme='TTY_CHANGE_THEME'
TTY_CHANGE_THEME() {
local LOCAL_THEME_LINK="$HOME/.config/wryn/tty-colorscheme"
local THEME_DIR="$DOTWRYN/config/colorschemes/kitty"
local THEME="$1"
[ ! $THEME ] && {
THEME=$(GET_TTY_THEMES | FZF_THEME_PICK)
[ ! $THEME ] && return 1
}
[[ "$THEME" =~ ^default ]] && {
rm $LOCAL_THEME_LINK >/dev/null 2>&1
true
} || {
local COLORSCHEME="$THEME_DIR/$THEME"
[ ! -f $COLORSCHEME ] && { echo "no such theme ($THEME)"; return 2; }
rm -- $LOCAL_THEME_LINK >/dev/null 2>&1
ln -s $SOURCE_THEME $TARGET_THEME_LINK
}
echo 'TTY theme updated; re-source zshrc in TTY for changes to take effect'
source "$DOTWRYN/config/colorschemes/linux-console" >/dev/null 2>&1
}
_TTY_CHANGE_THEME() { compadd $(GET_TTY_THEMES); }
compdef _TTY_CHANGE_THEME TTY_CHANGE_THEME