dotfiles-pub/common/.zshrc

184 lines
5.4 KiB
Bash
Raw Normal View History

2022-03-25 00:01:22 +00:00
if [[ ! -d "$HOME/.zsh" ]]; then
2022-03-23 04:40:21 +00:00
mkdir -p ~/.zsh
fi
2022-02-15 21:07:11 +00:00
fpath=(~/.zsh $fpath)
2022-03-25 00:01:22 +00:00
if [[ ! -d "$HOME/.zsh/gitstatus" ]]; then
2022-03-23 04:40:21 +00:00
git clone --depth=1 https://github.com/romkatv/gitstatus.git ~/.zsh/gitstatus
fi
source ~/.zsh/gitstatus/gitstatus.plugin.zsh
2022-02-15 21:07:11 +00:00
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
# End of lines configured by zsh-newuser-install
####
#autoload -Uz vcs_info
#precmd_vcs_info() {
# vcs_info
# local STATUS=$(git status --porcelain 2> /dev/null | tail -1)
# if [[ -n $STATUS ]]; then
# zstyle ':vcs_info:git:*' formats '%F{cyan}%b%f %F{yellow}▲%f '
# else
# zstyle ':vcs_info:git:*' formats '%F{cyan}%b%f %F{green}▲%f '
# fi
#}
#precmd_functions+=( precmd_vcs_info )
#
#zstyle ':vcs_info:*' enable git
setopt prompt_subst
#get_git_branch() {
# git symbolic-ref --short HEAD 2> /dev/null
#}
#
#get_git_dirty() {
# git status --porcelain 2> /dev/null
#}
#
#git_status=""
#get_git_status() {
# git_status=""
# local BRANCH=$(get_git_branch)
# local STATUS=$(get_git_dirty)
# if [[ -n $BRANCH ]]; then
# if [[ -n $STATUS ]]; then
# git_status="%F{cyan}$BRANCH%f %F{yellow}▲%f "
# else
# git_status="%F{cyan}$BRANCH%f %F{green}▲%f "
# fi
# fi
#}
#
#precmd_functions+=(get_git_status)
git_status=""
git_status_v2() {
git_status=""
if gitstatus_query PROMPT && [[ $VCS_STATUS_RESULT == ok-sync ]]; then
local DIRTY=0
if [[ $VCS_STATUS_NUM_UNSTAGED -gt 0 ]] || [[ $VCS_STATUS_NUM_UNTRACKED -gt 0 ]]; then
DIRTY=1
fi
2022-02-15 21:07:11 +00:00
if [[ $DIRTY -eq 1 ]]; then
git_status="%F{cyan}$VCS_STATUS_LOCAL_BRANCH%f %F{yellow}▲%f "
2022-02-15 21:07:11 +00:00
else
git_status="%F{cyan}$VCS_STATUS_LOCAL_BRANCH%f %F{green}▲%f "
2022-02-15 21:07:11 +00:00
fi
fi
}
precmd_functions+=(git_status_v2)
gitstatus_stop 'PROMPT' && gitstatus_start -s -1 -u -1 -c -1 -d -1 'PROMPT'
2022-02-15 21:07:11 +00:00
timer=0
timer_show=0
preexec_time() {
timer=${timer:-$SECONDS}
}
precmd_time() {
if [ $timer ]; then
timer_show=$(($SECONDS-$timer))
unset timer
fi
}
preexec_functions+=(preexec_time)
precmd_functions+=(precmd_time)
prompt_time() {
local out=""
if [ $timer_show -lt 3 ]; then
timer_display=$out
return
fi
if [ $timer_show -ge 3600 ]; then
out+="$(printf '%d' $(($timer_show/3600)))h"
fi
if [ $timer_show -ge 60 ]; then
out+="$(printf '%d' $(($timer_show%3600/60)))m"
fi
out+="$(printf '%d' $(($timer_show%60)))s"
timer_display=$out
}
precmd_functions+=(prompt_time)
binary_clock() {
local row0=("" "⠈" "⠐" "⠘" "⠠" "⠨" "⠰" "⠸" "⢀" "⢈")
local row1=("⠁" "⠉" "⠑" "⠙" "⠡" "⠩" "⠱" "⠹" "⢁" "⢉")
local row2=("⠂" "⠊" "⠒" "⠚" "⠢" "⠪" "⠲" "⠺" "⢂" "⢊")
local row3=("⠃" "⠋" "⠓" "⠛" "⠣" "⠫" "⠳" "⠻" "⢃" "⢋")
local row4=("⠄" "⠌" "⠔" "⠜" "⠤" "⠬" "⠴" "⠼" "⢄" "⢌")
local row5=("⠅" "⠍" "⠕" "⠝" "⠥" "⠭" "⠵" "⠽" "⢅" "⢍")
local chars=("${row0[@]}" "${row1[@]}" "${row2[@]}" "${row3[@]}" "${row4[@]}" "${row5[@]}")
local hour=$(date +"%H")
local minute=$(date +"%M")
local second=$(date +"%S")
[[ $hour = 0* ]] && hour=${hour:1:1}
[[ $minute = 0* ]] && minute=${minute:1:1}
[[ $second = 0* ]] && second=${second:1:1}
bclock="${chars[$hour+1]} ${chars[$minute+1]} ${chars[$second+1]}"
}
precmd_functions+=(binary_clock)
PROMPT=' %(?.%F{magenta}.%F{red})λ%f %1~ $git_status '
2022-02-15 21:07:11 +00:00
RPROMPT='%F{yellow}$timer_display%f %(?..%F{red}%?%f )%F{white}$bclock%f'
####
# keys
autoload -Uz up-line-or-beginning-search
autoload -Uz down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey '^?' backward-delete-char # bs delete one char backward
bindkey '^[[3~' delete-char # delete delete one char forward
bindkey '^[[P' delete-char # delete (2) delete one char forward
2022-02-15 21:07:11 +00:00
bindkey '^[[H' beginning-of-line # home go to the beginning of line
bindkey '^[[F' end-of-line # end go to the end of line
bindkey '^[[1~' beginning-of-line # home (2) go to the beginning of line
bindkey '^[[4~' end-of-line # end (2) go to the end of line
bindkey '^[[1;5C' forward-word # ctrl+right go forward one word
bindkey '^[[1;5D' backward-word # ctrl+left go backward one word
bindkey '^H' backward-kill-word # ctrl+bs delete previous word
bindkey '^[[3;5~' kill-word # ctrl+del delete next word
bindkey '^J' backward-kill-line # ctrl+j delete everything before cursor
bindkey '^[[D' backward-char # left move cursor one char backward
bindkey '^[[C' forward-char # right move cursor one char forward
bindkey '^[[A' up-line-or-beginning-search # up prev command in history
bindkey '^[[B' down-line-or-beginning-search # down next command in history
bindkey '^[[5~' history-search-backward # pgup prev in history no search
bindkey '^[[6~' history-search-forward # pgdn next in history no search
####
2022-03-24 23:44:23 +00:00
# aliases
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias cls='clear'
alias del='rm'
####
2022-02-15 21:07:11 +00:00
# hast =)
hast() { a=$(cat); curl -X POST -s -d "$a" https://haste.soulja-boy-told.me/documents | awk -F '"' '{print "https://haste.soulja-boy-told.me/"$4}'; }
####
export PATH=$PATH:$HOME/.local/bin