99 lines
3.0 KiB
Bash
99 lines
3.0 KiB
Bash
#!/bin/zsh
|
|
#####################################################################
|
|
|
|
alias ls='ls --color=auto --group-directories-first'
|
|
|
|
#####################################################################
|
|
|
|
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)
|
|
[[ $PROJECT_NAME =~ code ]] && PROJECT_NAME=$(basename $(dirname $GIT_ROOT))
|
|
|
|
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
|
|
}
|
|
|
|
GENERATE_PS1() {
|
|
|
|
local _INDICATOR="%B%(?.%F{green}.%F{red}) $PS1_INDICATOR_SYMBOL"
|
|
local _USER="%B%F{magenta}$PS1_USER"
|
|
local _SEPARATOR="%b%F{red}$PS1_SEPARATOR"
|
|
local _DIRECTORY='$(PS1__GET_DIRECTORY)'
|
|
local _GIT_BRANCH='$(PS1__GET_GIT_BRANCH)'
|
|
|
|
local _PROMPT=$'\n'' %B%F{blue}%# %b%f'
|
|
|
|
echo "$_INDICATOR $_USER $_SEPARATOR $_DIRECTORY $_GIT_BRANCH $_PROMPT"
|
|
}
|
|
|
|
setopt PROMPT_SUBST
|
|
export PS1="$(GENERATE_PS1)"
|
|
|
|
#####################################################################
|
|
|
|
source "$DOTWRYN/config/colorschemes/linux-console"
|
|
|
|
alias tty-change-theme='TTY_CHANGE_THEME'
|
|
function TTY_CHANGE_THEME() {
|
|
local TARGET_THEME_LINK="$HOME/.config/wryn/tty-colorscheme"
|
|
local SOURCE_THEME="$DOTWRYN/config/colorschemes/kitty/$1"
|
|
|
|
[ ! $1 ] && { echo must specify colorscheme; return 1; }
|
|
|
|
[[ $1 =~ ^current-kitty-theme$ ]] && {
|
|
rm $TARGET_THEME_LINK >/dev/null 2>&1
|
|
} || {
|
|
[ ! -f $SOURCE_THEME ] && { echo no such colorscheme; return 2; }
|
|
|
|
rm $TARGET_THEME_LINK >/dev/null 2>&1
|
|
ln -s $SOURCE_THEME $TARGET_THEME_LINK
|
|
}
|
|
|
|
echo 'TTY colorscheme updated; resource shell in TTY for changes to take effect'
|
|
source "$DOTWRYN/config/colorschemes/linux-console"
|
|
}
|
|
_TTY_CHANGE_THEME() {
|
|
compadd $(ls $DOTWRYN/config/colorschemes/kitty) current-kitty-theme
|
|
}
|
|
compdef _TTY_CHANGE_THEME TTY_CHANGE_THEME;
|
|
|
|
#####################################################################
|
|
|
|
alias kitty-change-theme='KITTY_CHANGE_THEME default'
|
|
alias kitty-change-theme-alternate='KITTY_CHANGE_THEME alternate'
|
|
function KITTY_CHANGE_THEME () {
|
|
[ ! $2 ] && echo no filename given :c && return 1;
|
|
[ ! -f "$DOTWRYN/config/colorschemes/kitty/$2" ] \
|
|
&& echo colorscheme not supported && return 2;
|
|
|
|
local THEME_DIR="$DOTWRYN/config/kitty";
|
|
local THEME;
|
|
[ $1 = 'default' ] && THEME="$THEME_DIR/theme.conf" || THEME="$THEME_DIR/alternate.conf"
|
|
rm "$THEME"
|
|
ln -s "$DOTWRYN/config/colorschemes/kitty/$2" "$THEME"\
|
|
&& echo 'theme changed successfully! (effective on new terminal session)'
|
|
|
|
[ -f "$HOME/.config/wryn/tty-colorscheme" ] && source "$HOME/.config/wryn/tty-colorscheme"
|
|
}
|
|
_KITTY_CHANGE_THEME () {
|
|
compadd $(ls $DOTWRYN/config/colorschemes/kitty)
|
|
}
|
|
compdef _KITTY_CHANGE_THEME KITTY_CHANGE_THEME;
|