Migrating to zsh; made envvars generic to bash and zsh
This commit is contained in:
parent
9f9774c25c
commit
2728b992d6
5 changed files with 413 additions and 18 deletions
19
bashrc
19
bashrc
|
@ -1,23 +1,6 @@
|
|||
source .profile
|
||||
if [[ $- != *i* ]] ; then
|
||||
# Shell is non-interactive. Be done now!
|
||||
return
|
||||
fi
|
||||
|
||||
# The city's finest exports!
|
||||
export GIT_EDITOR="vim"
|
||||
export PATH="$PATH:$HOME/.local/bin"
|
||||
export PS1="\[$(tput setaf 2)\]\u@\h\[$(tput setaf 4)\] \w\[$(tput sgr0)\] \\$ "
|
||||
export TERM=xterm-color # Fixes ssh since I use alacritty and it sets the TERM to its name
|
||||
export VIMINIT="source $HOME/.config/vim/vimrc"
|
||||
|
||||
# Setting up the city's powerlines
|
||||
if [ -f $HOME/.local/lib/python3.9/site-packages/powerline/bindings/bash/powerline.sh ]; then
|
||||
powerline-daemon -q
|
||||
POWERLINE_BASH_CONTINUATION=1
|
||||
POWERLINE_BASH_SELECT=1
|
||||
. $HOME/.local/lib/python3.9/site-packages/powerline/bindings/bash/powerline.sh
|
||||
fi
|
||||
|
||||
alias ls="ls -h --color=auto"
|
||||
alias myip="curl https://ifconfig.co"
|
||||
alias steam="HOME=${HOME}/Games/steam steam"
|
||||
|
|
11
profile
Normal file
11
profile
Normal file
|
@ -0,0 +1,11 @@
|
|||
# The city's finest exports!
|
||||
export GIT_EDITOR="vim"
|
||||
export PATH="$PATH:$HOME/.local/bin"
|
||||
#export TERM=xterm-256color # Fixes ssh since I use alacritty and it sets the TERM to its name
|
||||
export VIMINIT="source $HOME/.config/vim/vimrc"
|
||||
|
||||
alias ls="ls -h --color=auto"
|
||||
alias myip="curl https://ifconfig.co"
|
||||
alias steam="HOME=${HOME}/Games/steam steam"
|
||||
alias wget="wget --hsts-file $HOME/.cache/wget/hsts"
|
||||
|
167
zprompts/bunni.zsh
Normal file
167
zprompts/bunni.zsh
Normal file
|
@ -0,0 +1,167 @@
|
|||
# Based on elite2 and mutahar's prompt on a youtube video (probably a default one on kali linux)
|
||||
## Created by Bunni
|
||||
## Edited by Siina to add gitstatus
|
||||
|
||||
prompt_bunni_help () {
|
||||
cat <<EOH
|
||||
This prompt is color-scheme-able. You can invoke it thus:
|
||||
|
||||
$ prompt bunni [-t <text-color>] [-p <punctuation-color>]
|
||||
[-b <background-color>] [-f <bold/double/default>]
|
||||
|
||||
The default text and punctuation colors are none, with a blue background.
|
||||
This theme works best with a dark background.
|
||||
|
||||
Recommended fonts for this theme: either UTF-8, or nexus or vga or similar.
|
||||
If you don't have any of these, the 8-bit characters will probably look
|
||||
bad.
|
||||
EOH
|
||||
}
|
||||
|
||||
prompt_bunni_setup () {
|
||||
# Set defaults
|
||||
## Color
|
||||
local default_color1='%f'
|
||||
local default_color2='%f'
|
||||
local default_color3='%K{blue}'
|
||||
local text_col=${default_color1}
|
||||
local punct_col=${default_color2}
|
||||
local back_col=${default_color3}
|
||||
## Punct
|
||||
local U2500="─"
|
||||
local U250C="┌"
|
||||
local U2514="└"
|
||||
local U2501="━"
|
||||
local U250F="┏"
|
||||
local U2517="┗"
|
||||
local U2550="═"
|
||||
local U2554="╔"
|
||||
local U255A="╚"
|
||||
local dash="$U2500"
|
||||
local ulCorner="$U250C"
|
||||
local dlCorner="$U2514"
|
||||
|
||||
while [ "$#" -gt "1" ]
|
||||
do
|
||||
case $1 in
|
||||
'-T'|'--theme'*)
|
||||
# User made themes. Feel free to change them.
|
||||
theme=$2
|
||||
case $theme in
|
||||
'user')
|
||||
text_col='%F{yellow}'
|
||||
;;
|
||||
'admin')
|
||||
text_col='%F{cyan}'
|
||||
;;
|
||||
'root')
|
||||
text_col='%f'
|
||||
;;
|
||||
esac
|
||||
shift 2
|
||||
;;
|
||||
'-t'|'--text'*)
|
||||
if [ "$2" = "" ]
|
||||
then
|
||||
text_col='%f'
|
||||
else
|
||||
text_col="%F{$2}"
|
||||
fi
|
||||
shift 2
|
||||
;;
|
||||
'-p'|'--punctuation'*)
|
||||
if [ "$2" = "" ]
|
||||
then
|
||||
punct_col='%f'
|
||||
else
|
||||
punct_col="%F{$2}"
|
||||
fi
|
||||
shift 2
|
||||
;;
|
||||
'-b'|'--background'*)
|
||||
if [ "$2" = "" ]
|
||||
then
|
||||
back_col='%f'
|
||||
else
|
||||
back_col="%K{$2}"
|
||||
fi
|
||||
shift 2
|
||||
;;
|
||||
'-f'|'--form'*)
|
||||
case $2 in
|
||||
'b'|'bold')
|
||||
dash="$U2501"
|
||||
ulCorner="$U250F"
|
||||
dlCorner="$U2517"
|
||||
;;
|
||||
'd'|'double')
|
||||
dash="$U2550"
|
||||
ulCorner="$U2554"
|
||||
dlCorner="$U255A"
|
||||
;;
|
||||
*)
|
||||
dash="$U2500"
|
||||
ulCorner="$U250C"
|
||||
dlCorner="$U2514"
|
||||
;;
|
||||
esac
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
#prompt_bunni_help
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Assemble
|
||||
|
||||
local text="%b$text_col%k"
|
||||
local parens="%B$punct_col%k"
|
||||
local punct="%B$punct_col%k"
|
||||
local background="%b%f$back_col"
|
||||
local reset="%b%f%k"
|
||||
|
||||
local lpar="$parens($text"
|
||||
local rpar="$parens)$text"
|
||||
local lbra="$parens"'['"$text"
|
||||
local rbra="$parens"']'"$text"
|
||||
|
||||
source $HOME/Projects/dotfiles/zprompts/gitstatus.plugin.zsh
|
||||
setopt PROMPT_SUBST
|
||||
|
||||
local gitstatus=' $(gitstatus -i)'
|
||||
|
||||
PS1="$punct$ulCorner$dash$dash$text$lpar$background%n@%m$rpar$punct$dash$text$lbra%B%~$rbra$punct$reset$gitstatus$prompt_newline$punct$dlCorner$dash\$$reset "
|
||||
|
||||
PS2="$parens$text$punct-$reset "
|
||||
|
||||
prompt_opts=(cr subst percent)
|
||||
}
|
||||
|
||||
prompt_bunni_preview () {
|
||||
local color colors options
|
||||
# 1 1 1 2 2 2
|
||||
colors=('' '' 'user' 'green' 'magenta' '') # they go in groups of 3: text color, punctuation color, theme
|
||||
|
||||
if (( ! $#* )); then
|
||||
s=3
|
||||
for i in `seq 1 $s $#colors`; do
|
||||
j=$(( $i + 1 ))
|
||||
k=$(( $i + 2 ))
|
||||
color=$colors[$i]
|
||||
color2=$colors[$j]
|
||||
color3=$colors[$k]
|
||||
options=()
|
||||
[[ ! "$color" = '' ]] && options=($options '--textColor' "$color")
|
||||
[[ ! "$color2" = '' ]] && options=($options '--punctuationColor' "$color2")
|
||||
[[ ! "$color3" = '' ]] && options=($options '--theme' "$color3")
|
||||
prompt_preview_theme bunni $options
|
||||
(( i < $(($#colors - $s)) )) && print
|
||||
done
|
||||
else
|
||||
prompt_preview_theme bunni "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_bunni_setup "$@"
|
172
zprompts/gitstatus.plugin.zsh
Executable file
172
zprompts/gitstatus.plugin.zsh
Executable file
|
@ -0,0 +1,172 @@
|
|||
###
|
||||
# Print the final gitstatus prompt to stdout
|
||||
# Arguments: $1 -i, if it's an inline prompt => add a whitespace at the end, if
|
||||
# not empty
|
||||
#
|
||||
#
|
||||
# Original: https://github.com/xylous/gitstatus
|
||||
###
|
||||
function gitstatus()
|
||||
{
|
||||
is_in_git_repository || return 1
|
||||
|
||||
parse_git_status
|
||||
local modified="${STATUS[1]}"
|
||||
local staged="${STATUS[2]}"
|
||||
local deleted="${STATUS[3]}"
|
||||
local untracked="${STATUS[4]}"
|
||||
unset STATUS
|
||||
|
||||
git_grab_current_branch
|
||||
local branch="$REPLY"
|
||||
|
||||
git_grab_remote_branch
|
||||
local remote="$REPLY"
|
||||
|
||||
[[ ! -z "$remote" ]] \
|
||||
&& git_local_remote_diffs "$branch" "$remote" \
|
||||
&& local commit_diffs="$REPLY"
|
||||
|
||||
git_determine_color $modified $staged $deleted $untracked
|
||||
local color="$REPLY"
|
||||
|
||||
(( modified > 0 )) \
|
||||
&& modified="!$modified "
|
||||
(( staged > 0 )) \
|
||||
&& staged="+$staged "
|
||||
(( deleted > 0 )) \
|
||||
&& deleted="-$deleted "
|
||||
(( untracked > 0 )) \
|
||||
&& untracked="?$untracked "
|
||||
|
||||
local output="$color"
|
||||
output+=" $branch "
|
||||
output+="$commit_diffs"
|
||||
output+="$modified"
|
||||
output+="$staged"
|
||||
output+="$deleted"
|
||||
output+="$untracked"
|
||||
|
||||
local true_output="$(sed 's/[ \t]*$//' <<<"$output")" # remove trailing whitespace
|
||||
|
||||
if [[ "$1" == "-i" ]]; then
|
||||
true_output+=" "
|
||||
fi
|
||||
|
||||
true_output+=$'%F{default}'
|
||||
echo "${true_output}"
|
||||
|
||||
unset REPLY
|
||||
}
|
||||
|
||||
###
|
||||
# Check if we're in a git repository
|
||||
# Arguments: none
|
||||
# Returns: 0 if in a git repo, 1 otherwise
|
||||
###
|
||||
function is_in_git_repository()
|
||||
{
|
||||
git rev-parse --git-dir &>/dev/null || return 1
|
||||
}
|
||||
|
||||
###
|
||||
# Return current branch we're on
|
||||
# Arguments: none
|
||||
###
|
||||
function git_grab_current_branch()
|
||||
{
|
||||
typeset -g REPLY="$(git branch --show-current)"
|
||||
}
|
||||
|
||||
###
|
||||
# Return remote branch that the local one is tracking
|
||||
# Arguemnts: none
|
||||
###
|
||||
function git_grab_remote_branch()
|
||||
{
|
||||
local symbolic_ref="$(git symbolic-ref -q HEAD)"
|
||||
typeset -g REPLY="$(git for-each-ref --format='%(upstream:short)' "$symbolic_ref")"
|
||||
}
|
||||
|
||||
###
|
||||
# Find how many things have changed since last git commit
|
||||
# Arguments: none
|
||||
###
|
||||
function parse_git_status()
|
||||
{
|
||||
git status --porcelain=v1 | while IFS= read -r status_line; do
|
||||
case "$status_line" in
|
||||
' M '*)
|
||||
((modified++))
|
||||
;;
|
||||
'A '*|'M '*)
|
||||
((staged++))
|
||||
;;
|
||||
' D '*)
|
||||
((deleted++))
|
||||
;;
|
||||
'?? '*)
|
||||
((untracked++))
|
||||
;;
|
||||
'MM '*)
|
||||
((staged++))
|
||||
((modified++))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
typeset -g STATUS=("$modified" "$staged" "$deleted" "$untracked")
|
||||
return 0
|
||||
}
|
||||
|
||||
###
|
||||
# Look at how many commits a local branch is ahead/behind of remote branch
|
||||
# Arguments: $1 local branch
|
||||
# $2 remote branch
|
||||
###
|
||||
function git_local_remote_diffs()
|
||||
{
|
||||
local local_branch="$1"
|
||||
local remote_branch="$2"
|
||||
|
||||
local differences="$(git rev-list --left-right --count $local_branch...$remote_branch)"
|
||||
local commits_ahead=$(echo -n "$differences" | awk '{print $1}')
|
||||
local commits_behind=$(echo -n "$differences" | awk '{print $2}')
|
||||
local ahead="" behind=""
|
||||
|
||||
local result=""
|
||||
|
||||
(( $commits_ahead > 0 )) \
|
||||
&& ahead="↑$commits_ahead"
|
||||
(( $commits_behind > 0 )) \
|
||||
&& behind="↓$commits_behind"
|
||||
|
||||
if [[ ! -z "${ahead}" ]]; then
|
||||
result="${ahead} "
|
||||
fi
|
||||
|
||||
if [[ ! -z "${behind}" ]]; then
|
||||
result="${behind} "
|
||||
fi
|
||||
|
||||
typeset -g REPLY="${result}"
|
||||
}
|
||||
|
||||
###
|
||||
# If there is anything that changed from the past commit, return yellow.
|
||||
# Otherwise, green.
|
||||
# Arguments: list of how many things changed
|
||||
###
|
||||
function git_determine_color()
|
||||
{
|
||||
local green=$'%F{yellow}'
|
||||
local yellow=$'%F{green}'
|
||||
for i in "$@"; do
|
||||
if (( $i > 0 )); then
|
||||
typeset -g REPLY="$green"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
typeset -g REPLY="$yellow"
|
||||
return 0
|
||||
}
|
62
zshrc
Normal file
62
zshrc
Normal file
|
@ -0,0 +1,62 @@
|
|||
# Add our zprompts to fpath to use bunni theme
|
||||
fpath=("$HOME/.config/zsh/zprompts" "$fpath[@]")
|
||||
|
||||
autoload -U compinit promptinit
|
||||
|
||||
# move zcompdump to the cache folder
|
||||
if [ ! -d "$HOME/.cache/zsh" ]; then
|
||||
mkdir $HOME/.cache/zsh
|
||||
fi
|
||||
compinit -d $HOME/.cache/zsh/zcompdump
|
||||
|
||||
# Thanks, sweet bunni, for sharing your theme <3
|
||||
promptinit; prompt bunni -b none -t blue
|
||||
|
||||
# Let's grab our generic envvars and aliases
|
||||
source $HOME/.profile
|
||||
|
||||
## Keybinds from Arch Wiki
|
||||
# create a zkbd compatible hash;
|
||||
# to add other keys to this hash, see: man 5 terminfo
|
||||
typeset -g -A key
|
||||
|
||||
key[Home]="${terminfo[khome]}"
|
||||
key[End]="${terminfo[kend]}"
|
||||
key[Insert]="${terminfo[kich1]}"
|
||||
key[Backspace]="${terminfo[kbs]}"
|
||||
key[Delete]="${terminfo[kdch1]}"
|
||||
key[Up]="${terminfo[kcuu1]}"
|
||||
key[Down]="${terminfo[kcud1]}"
|
||||
key[Left]="${terminfo[kcub1]}"
|
||||
key[Right]="${terminfo[kcuf1]}"
|
||||
key[PageUp]="${terminfo[kpp]}"
|
||||
key[PageDown]="${terminfo[knp]}"
|
||||
key[Shift-Tab]="${terminfo[kcbt]}"
|
||||
key[Control-Left]="${terminfo[kLFT5]}"
|
||||
key[Control-Right]="${terminfo[kRIT5]}"
|
||||
|
||||
# setup key accordingly
|
||||
[[ -n "${key[Home]}" ]] && bindkey -- "${key[Home]}" beginning-of-line
|
||||
[[ -n "${key[End]}" ]] && bindkey -- "${key[End]}" end-of-line
|
||||
[[ -n "${key[Insert]}" ]] && bindkey -- "${key[Insert]}" overwrite-mode
|
||||
[[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}" backward-delete-char
|
||||
[[ -n "${key[Delete]}" ]] && bindkey -- "${key[Delete]}" delete-char
|
||||
[[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-history
|
||||
[[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-history
|
||||
[[ -n "${key[Left]}" ]] && bindkey -- "${key[Left]}" backward-char
|
||||
[[ -n "${key[Right]}" ]] && bindkey -- "${key[Right]}" forward-char
|
||||
[[ -n "${key[PageUp]}" ]] && bindkey -- "${key[PageUp]}" beginning-of-buffer-or-history
|
||||
[[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" end-of-buffer-or-history
|
||||
[[ -n "${key[Shift-Tab]}" ]] && bindkey -- "${key[Shift-Tab]}" reverse-menu-complete
|
||||
[[ -n "${key[Control-Left]}" ]] && bindkey -- "${key[Control-Left]}" backward-word
|
||||
[[ -n "${key[Control-Right]}" ]] && bindkey -- "${key[Control-Right]}" forward-word
|
||||
|
||||
# Finally, make sure the terminal is in application mode, when zle is
|
||||
# active. Only then are the values from $terminfo valid.
|
||||
if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
|
||||
autoload -Uz add-zle-hook-widget
|
||||
function zle_application_mode_start { echoti smkx }
|
||||
function zle_application_mode_stop { echoti rmkx }
|
||||
add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
|
||||
add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
|
||||
fi
|
Loading…
Reference in a new issue