This commit is contained in:
Out Of Ideas 2024-06-04 12:14:55 -05:00
parent 01a5ab69f6
commit d91ef547b5

619
config/zsh/.zshrc Normal file
View file

@ -0,0 +1,619 @@
#!/bin/zsh
#############
# Autostart #
#############
# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi
if [ -e /home/vehementham/.nix-profile/etc/profile.d/nix.sh ]; then . /home/vehementham/.nix-profile/etc/profile.d/nix.sh; fi # added by Nix installer
#source .profile
##########
# Prompt #
##########
if [[ $(tty) != "/dev/tty"* ]]; then
eval "$(starship init zsh)"
else
autoload -U colors && colors
# No Directory Shortening
#PS1="%{$fg[cyan]%}%n%{$reset_color%}@%{$fg[red]%}%m %{$fg[magenta]%}%~ %{$reset_color%}%% "
# Directory Shortening
PS1="%{$fg[cyan]%}%n%{$reset_color%}@%{$fg[red]%}%m %{$fg[magenta]%}%(5~|%-1~/.../%3~|%4~) %{$reset_color%}%% "
fi
###########
# Aliases #
###########
alias doas="doas "
alias neofetch="clear && neofetch"
alias fastfetch="clear && fastfetch"
alias audio-dlp="yt-dlp -f \"bestaudio\" --extract-audio --audio-format vorbis"
alias hfnn="fc -ln 0"
alias psrc="/usr/pkg/bin/bmake package-install"
alias cmd="command"
alias fetch="fastfetch"
alias copy="wl-copy"
alias c="cd"
alias e="eza"
# If eza is not installed check if exa is installed, and if that is not installed, alias to ls
if type eza &> /dev/null; then
alias eza="eza --long --icons --git --no-permissions"
alias e="eza"
alias ea="eza -a"
elif type exa &> /dev/null; then
alias exa="eza --long --icons --git --no-permissions"
alias e="exa"
alias ea="exa -a"
else
alias e="ls"
alias ea="ls -a"
fi
# If bat is not installed, alias to cat
if type pygmentize &> /dev/null; then
alias bat="pygmentize -P style=tomorrownight"
alias b="pygmentize -P style=tomorrownight"
else
alias b="cat"
fi
alias pn="ping"
alias ew="eww"
alias n="nvim"
alias d="pwd"
alias k="rm"
alias y="cp"
alias no="nano"
alias v="vi"
alias vm="vim"
alias vs="vis"
alias j="ed"
alias l="ex"
alias f="find"
alias src="source"
alias gr="grep"
alias g="git"
alias ga="git add"
alias gaa="git add -A"
alias gc="git commit -m"
alias gp="git push"
alias gch="git checkout"
alias gcl="git clone"
alias gpl="git pull"
alias p="pkg"
alias ap="apk"
alias ap="doas apk add"
alias apd="doas apk del"
alias aps="apk search"
alias api="apk info"
alias apuu="doas apk update && doas apk upgrade"
alias apu="doas apk update"
alias pa="pkg_add"
alias pi="pkg_info"
alias cm="chmod"
alias cr="chroot"
alias da="doas"
alias s="su"
alias sd="sudo"
alias mk="make"
alias mkd="mkdir"
alias x="mv"
alias m="mg"
alias em="emacs"
alias tn="ping suckless.org"
alias mnt="mount"
alias u="dd"
alias wai="whoami"
alias h="echo"
alias a="awk"
alias se="sed"
alias bctl="bluetoothctl"
alias sysctl="systmemsytl"
alias ru="doas rc-update"
alias rua="doas rc-update add"
alias rs="rc-service"
alias mp="modprobe"
alias pl="mpv"
alias w="which"
alias i="install"
alias rn="rename"
alias t="tr"
alias loc="locate"
alias wi="whereis"
alias get_ip='ip addr | grep -e wlp -e wlan -e enp -e "eth<->" | grep inet | head -1 | awk '"'"'{print $2}'"'"' | awk -F/ '"'"'{print $1}'"'"''
###########################
# Environmental Variables #
###########################
# Man
#export MANPAGER='nvim +Man!'
# Bat
BAT_PAGER=""
# Terminal Emulator
#export TERM=foot
export TERM=xterm-256color
# Configuration Directory
export XDG_CONFIG_DIR="$HOME/.config"
# Vis Path
VIS_PATH="$XDG_CONGIG_DIR/vis"
# Dbus
export $(dbus-launch)
###########
# Plugins #
###########
# Directory Variables
PLUGIN_PATH="$HOME/.config/zsh/plugins"
SYNTAX_HIGHLIGHTING_PATH="$PLUGIN_PATH/F-Sy-H/F-Sy-H.plugin.zsh"
AUTOSUGGESTIONS_PATH="$PLUGIN_PATH/zsh-autosuggestions/zsh-autosuggestions.zsh"
HISTORY_SUBSTRING_SEARCH_PATH="$PLUGIN_PATH/zsh-history-substring-search/zsh-history-substring-search.zsh"
Z_PATH="$PLUGIN_PATH/z-zsh/z-zsh.zsh/zsh-z.plugin.zsh"
YOU_SHOULD_USE_PATH="$PLUGIN_PATH/zsh-you-should-use/you-should-use.plugin.zsh"
AUTO_NOTIFY_PATH="$PLUGIN_PATH/zsh-auto-notify/auto-notify.plugin.zsh"
HISTORY_SEARCH_PATH="$PLUGIN_PATH/H-S-MW/H-S-MW.plugin.zsh"
# Install plugins if they are not already installed
if ! ls $SYNTAX_HIGHLIGHTING_PATH &> /dev/null; then
git clone https://github.com/z-shell/F-Sy-H $(dirname SYNTAX_HIGHLIGHTING_PATH)
fi
if ! ls $AUTOSUGGESTIONS_PATH &> /dev/null; then
git clone https://github.com/zsh-users/zsh-autosuggestions $(dirname $AUTOSUGGESTIONS_PATH)
fi
if ! ls $HISTORY_SUBSTRING_SEARCH_PATH &> /dev/null; then
git clone https://github.com/zsh-users/zsh-history-substring-search $(dirname $HISTORY_SUBSTRING_SEARCH_PATH)
fi
if ! ls $YOU_SHOULD_USE_PATH &> /dev/null; then
git clone https://github.com/MichaelAquilina/zsh-you-should-use $(dirname $YOU_SHOULD_USE_PATH)
fi
if ! ls $Z_PATH &> /dev/null; then
git clone https://github.com/agkozak/zsh-z $(dirname $Z_PATH)
fi
if ! ls $AUTO_NOTIFY_PATH &> /dev/null; then
git clone https://github.com/MichaelAquilina/zsh-auto-notify $(dirname $AUTO_NOTIFY_PATH)
fi
if ! ls $HISTORY_SEARCH_PATH &> /dev/null; then
git clone https://github.com/z-shell/H-S-MW $(dirname $HISTORY_SEARCH_PATH)
fi
# Syntax Highlighting
source $SYNTAX_HIGHLIGHTING_PATH
# Auto Suggestions
source $AUTOSUGGESTIONS_PATH
# Hisory Substring Search
source $HISTORY_SUBSTRING_SEARCH_PATH
# You should use
source $YOU_SHOULD_USE_PATH
# Z
source $Z_PATH
# Autonotify
source $AUTO_NOTIFY_PATH
# History search
source $HISTORY_SEARCH_PATH
##############
# Autonotify #
##############
export AUTO_NOTIFY_IGNORE=("docker" "man" "sleep" "vis" "mg" "vim" "nvim" "mpv" "emacs" "eww" "less" "watch" "htop" "top" "qemu" "qutebrowser" "imv" "lua5.3")
####################
# Foot Integration #
####################
function osc7-pwd() {
emulate -L zsh # also sets localoptions for us
setopt extendedglob
local LC_ALL=C
printf '\e]7;file://%s%s\e\' $HOST ${PWD//(#m)([^@-Za-z&-;_~])/%${(l:2::0:)$(([##16]#MATCH))}}
}
function chpwd-osc7-pwd() {
(( ZSH_SUBSHELL )) || osc7-pwd
}
add-zsh-hook -Uz chpwd chpwd-osc7-pwd
# Add functionality to pipe the output of the last command
function precmd {
if ! builtin zle; then
print -n "\e]133;D\e\\"
fi
}
function preexec {
print -n "\e]133;C\e\\"
}
##################
# Autocompletion #
##################
autoload -Uz compinit && compinit
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
###########
# History #
###########
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory
###############
# Keybindings #
###############
# Bind Alt + Delete for forward deleting a word
bindkey -M emacs '^[[3;3~' kill-word
# Bind Delete to delete a letter to the right
bindkey "^[[3~" delete-char
# Ctrl binds
# Bind Ctrl + Delete to delete word to the right
bindkey '^[[3;5~' kill-word
# Bind Ctrl + Backspace to delete word to the left
bindkey '^H' backward-kill-word
# Bind Ctrl + Right Arrow to move to the next word
bindkey '^[[1;5C' forward-word
# Bind Ctrl + Left Arrow to move to the previous word
bindkey '^[[1;5D' backward-word
# Hisory Substring Search Options
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
################
# Shift Select #
################
# for my own convenience I explicitly set the signals
# that my terminal sends to the shell as variables.
# you might have different signals. you can see what
# signal each of your keys sends by running `cat`
# and pressing keys (you'll be able to see most keys)
# also some of the signals sent might be set in your
# terminal emulator application/program
# configurations/preferences. finally some terminals
# have a feature that shows you what signals are sent
# per key press.
#
# for context, at the time of writing these variables are
# set for the kitty terminal program, i.e these signals
# are mostly ones sent by default by this terminal.
export KEY_ALT_B='^[b'
export KEY_ALT_D='^[d'
export KEY_ALT_F='^[f'
export KEY_CTRL_A='^A'
export KEY_CTRL_E='^E'
export KEY_CTRL_L='^L'
export KEY_CTRL_R='^R'
export KEY_CTRL_U='^U'
export KEY_CTRL_Z='^Z'
export KEY_SHIFT_CTRL_A='^[[27;6;65~'
export KEY_SHIFT_CTRL_C='^[[27;6;67~'
export KEY_SHIFT_CTRL_E='^[[27;6;69~'
export KEY_SHIFT_CTRL_V='^[[27;6;86~'
export KEY_SHIFT_CTRL_X='^[[27;6;88~'
export KEY_SHIFT_CTRL_Z='^[[27;6;90~'
export KEY_LEFT='^[[D'
export KEY_RIGHT='^[[C'
export KEY_SHIFT_UP='^[[1;2A'
export KEY_SHIFT_DOWN='^[[1;2B'
export KEY_SHIFT_RIGHT='^[[1;2C'
export KEY_SHIFT_LEFT='^[[1;2D'
export KEY_ALT_LEFT='^[[1;3D'
export KEY_ALT_RIGHT='^[[1;3C'
export KEY_SHIFT_ALT_LEFT='^[[1;4D'
export KEY_SHIFT_ALT_RIGHT='^[[1;6C'
export KEY_CTRL_LEFT='^[[1;5D'
export KEY_CTRL_RIGHT='^[[1;5C'
export KEY_SHIFT_CTRL_LEFT='^[[1;6D'
export KEY_SHIFT_CTRL_RIGHT='^[[1;6C'
export KEY_END='^[[F;'
export KEY_HOME='^[[H'
export KEY_SHIFT_END='^[[1;2F'
export KEY_SHIFT_HOME='^[[1;2H'
export KEY_DELETE='^[[3~'
export KEY_BACKSPACE='^?'
export KEY_CTRL_BACKSPACE='^H'
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# copy selected terminal text to clipboard
zle -N widget::copy-selection
function widget::copy-selection {
if ((REGION_ACTIVE)); then
zle copy-region-as-kill
if test "$XDG_SESSION_TYPE" = "x11"; then
printf "%s" $CUTBUFFER | xclip
elif test "$XDG_SESSION_TYPE" = "wayland"; then
printf "%s" $CUTBUFFER | wl-copy
fi
fi
}
# cut selected terminal text to clipboard
zle -N widget::cut-selection
function widget::cut-selection() {
if ((REGION_ACTIVE)) then
zle kill-region
if test "$XDG_SESSION_TYPE" = "x11"; then
printf "%s" $CUTBUFFER | xclip
elif test "$XDG_SESSION_TYPE" = "wayland"; then
printf "%s" $CUTBUFFER | wl-copy
fi
fi
}
# paste clipboard contents
zle -N widget::paste
function widget::paste() {
((REGION_ACTIVE)) && zle kill-region
# change to use xclip/wl-copy
if test "$XDG_SESSION_TYPE" = "x11"; then
RBUFFER="$(xclip -o -selection clipboard)${RBUFFER}"
CURSOR=$(( CURSOR + $(echo -n "$(xclip -o -selection clipboard)" | wc -m | bc) ))
elif test "$XDG_SESSION_TYPE" = "wayland"; then
RBUFFER="$(wl-paste)${RBUFFER}"
CURSOR=$(( CURSOR + $(echo -n "$(wl-paste)" | wc -m | bc) ))
fi
}
# select entire prompt
zle -N widget::select-all
function widget::select-all() {
local buflen=$(echo -n "$BUFFER" | wc -m | bc)
CURSOR=$buflen # if this is messing up try: CURSOR=9999999
zle set-mark-command
while [[ $CURSOR > 0 ]]; do
zle beginning-of-line
done
}
# scrolls the screen up, in effect clearing it
zle -N widget::scroll-and-clear-screen
function widget::scroll-and-clear-screen() {
printf "\n%.0s" {1..$LINES}
zle clear-screen
}
function widget::util-select() {
((REGION_ACTIVE)) || zle set-mark-command
local widget_name=$1
shift
zle $widget_name -- $@
zle copy-region-as-kill
printf "%s" $CUTBUFFER | wl-copy --primary
if test "$XDG_SESSION_TYPE" = "x11"; then
printf "%s" $CUTBUFFER | xclip -selection --primary
elif test "$XDG_SESSION_TYPE" = "wayland"; then
printf "%s" $CUTBUFFER | wl-copy --primary
fi
}
function widget::util-unselect() {
REGION_ACTIVE=0
local widget_name=$1
shift
zle $widget_name -- $@
}
function widget::util-delselect() {
if ((REGION_ACTIVE)) then
zle kill-region
else
local widget_name=$1
shift
zle $widget_name -- $@
fi
}
function widget::util-insertchar() {
((REGION_ACTIVE)) && zle kill-region
RBUFFER="${1}${RBUFFER}"
zle forward-char
}
# | key sequence | command
# --------------------- | ------------------------------- | -------------
bindkey $KEY_ALT_F forward-word
bindkey $KEY_ALT_B backward-word
bindkey $KEY_ALT_D kill-word
bindkey $KEY_CTRL_U backward-kill-line
bindkey $KEY_CTRL_BACKSPACE backward-kill-word
bindkey $KEY_CTRL_Z undo
bindkey $KEY_SHIFT_CTRL_Z redo
bindkey $KEY_CTRL_R history-incremental-search-backward
bindkey $KEY_SHIFT_CTRL_C widget::copy-selection
bindkey $KEY_SHIFT_CTRL_X widget::cut-selection
bindkey $KEY_SHIFT_CTRL_V widget::paste
bindkey $KEY_SHIFT_CTRL_A widget::select-all
bindkey $KEY_CTRL_L widget::scroll-and-clear-screen
for keyname kcap seq mode widget (
left kcub1 $KEY_LEFT unselect backward-char
right kcuf1 $KEY_RIGHT unselect forward-char
shift-up kri $KEY_SHIFT_UP select up-line-or-history
shift-down kind $KEY_SHIFT_DOWN select down-line-or-history
shift-right kRIT $KEY_SHIFT_RIGHT select forward-char
shift-left kLFT $KEY_SHIFT_LEFT select backward-char
alt-right x $KEY_ALT_RIGHT unselect forward-word
alt-left x $KEY_ALT_LEFT unselect backward-word
shift-alt-right x $KEY_SHIFT_ALT_RIGHT select forward-word
shift-alt-left x $KEY_SHIFT_ALT_LEFT select backward-word
ctrl-right x $KEY_CTRL_RIGHT unselect forward-word
ctrl-left x $KEY_CTRL_LEFT unselect backward-word
shift-cmd-right x $KEY_SHIFT_CTRL_RIGHT select end-of-line
shift-cmd-left x $KEY_SHIFT_CTRL_LEFT select beginning-of-line
ctrl-e x $KEY_CTRL_E unselect end-of-line
ctrl-a x $KEY_CTRL_A unselect beginning-of-line
shift-ctrl-e x $KEY_SHIFT_CTRL_E select end-of-line
shift-ctrl-a x $KEY_SHIFT_CTRL_A select beginning-of-line
shift-ctrl-right x $KEY_SHIFT_CTRL_RIGHT select forward-word
shift-ctrl-left x $KEY_SHIFT_CTRL_LEFT select backward-word
end kend $KEY_END unselect end-of-line
shift-end kEND $KEY_SHIFT_END select end-of-line
home khome $KEY_HOME unselect beginning-of-line
shift-home kHOM $KEY_SHIFT_HOME select beginning-of-line
del x $KEY_DELETE delselect delete-char
backspace x $KEY_BACKSPACE delselect backward-delete-char
a x 'a' insertchar 'a'
b x 'b' insertchar 'b'
c x 'c' insertchar 'c'
d x 'd' insertchar 'd'
e x 'e' insertchar 'e'
f x 'f' insertchar 'f'
g x 'g' insertchar 'g'
h x 'h' insertchar 'h'
i x 'i' insertchar 'i'
j x 'j' insertchar 'j'
k x 'k' insertchar 'k'
l x 'l' insertchar 'l'
m x 'm' insertchar 'm'
n x 'n' insertchar 'n'
o x 'o' insertchar 'o'
p x 'p' insertchar 'p'
q x 'q' insertchar 'q'
r x 'r' insertchar 'r'
s x 's' insertchar 's'
t x 't' insertchar 't'
u x 'u' insertchar 'u'
v x 'v' insertchar 'v'
w x 'w' insertchar 'w'
x x 'x' insertchar 'x'
y x 'y' insertchar 'y'
z x 'z' insertchar 'z'
A x 'A' insertchar 'A'
B x 'B' insertchar 'B'
C x 'C' insertchar 'C'
D x 'D' insertchar 'D'
E x 'E' insertchar 'E'
F x 'F' insertchar 'F'
G x 'G' insertchar 'G'
H x 'H' insertchar 'H'
I x 'I' insertchar 'I'
J x 'J' insertchar 'J'
K x 'K' insertchar 'K'
L x 'L' insertchar 'L'
M x 'M' insertchar 'M'
N x 'N' insertchar 'N'
O x 'O' insertchar 'O'
P x 'P' insertchar 'P'
Q x 'Q' insertchar 'Q'
R x 'R' insertchar 'R'
S x 'S' insertchar 'S'
T x 'T' insertchar 'T'
U x 'U' insertchar 'U'
V x 'V' insertchar 'V'
W x 'W' insertchar 'W'
X x 'X' insertchar 'X'
Y x 'Y' insertchar 'Y'
Z x 'Z' insertchar 'Z'
0 x '0' insertchar '0'
1 x '1' insertchar '1'
2 x '2' insertchar '2'
3 x '3' insertchar '3'
4 x '4' insertchar '4'
5 x '5' insertchar '5'
6 x '6' insertchar '6'
7 x '7' insertchar '7'
8 x '8' insertchar '8'
9 x '9' insertchar '9'
exclamation-mark x '!' insertchar '!'
hash-sign x '\#' insertchar '\#'
dollar-sign x '$' insertchar '$'
percent-sign x '%' insertchar '%'
ampersand-sign x '\&' insertchar '\&'
star x '\*' insertchar '\*'
plus x '+' insertchar '+'
comma x ',' insertchar ','
dot x '.' insertchar '.'
forwardslash x '\\' insertchar '\\'
backslash x '/' insertchar '/'
colon x ':' insertchar ':'
semi-colon x '\;' insertchar '\;'
left-angle-bracket x '\<' insertchar '\<'
right-angle-bracket x '\>' insertchar '\>'
equal-sign x '=' insertchar '='
question-mark x '\?' insertchar '\?'
left-square-bracket x '[' insertchar '['
right-square-bracket x ']' insertchar ']'
hat-sign x '^' insertchar '^'
underscore x '_' insertchar '_'
left-brace x '{' insertchar '{'
right-brace x '\}' insertchar '\}'
left-parenthesis x '\(' insertchar '\('
right-parenthesis x '\)' insertchar '\)'
pipe x '\|' insertchar '\|'
tilde x '\~' insertchar '\~'
at-sign x '@' insertchar '@'
dash x '\-' insertchar '\-'
double-quote x '\"' insertchar '\"'
single-quote x "\'" insertchar "\'"
backtick x '\`' insertchar '\`'
whitespace x '\ ' insertchar '\ '
) {
eval "function widget::key-$keyname() {
widget::util-$mode $widget \$@
}"
zle -N widget::key-$keyname
bindkey $seq widget::key-$keyname
}
# Fixes autosuggest completion being overriden by keybindings:
# to have [zsh] autosuggest [plugin feature] complete visible
# suggestions, you can assign an array of shell functions to
# the `ZSH_AUTOSUGGEST_ACCEPT_WIDGETS` variable. When these
# functions are triggered, they will also complete any visible
# suggestion. Example:
export ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
widget::key-right
widget::key-shift-right
widget::key-cmd-right
widget::key-shift-cmd-right
)