Skip to content

Commit

Permalink
Split .zshrc into multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
Akmadan23 committed Nov 16, 2023
1 parent e351f90 commit 6d0941b
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 250 deletions.
260 changes: 10 additions & 250 deletions config/zsh/.zshrc
Original file line number Diff line number Diff line change
@@ -1,261 +1,21 @@
# Case insensitive tab-completion
autoload -U compinit && compinit -d "$XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION"
zstyle ":completion:*" menu select
zstyle ":completion:*" matcher-list "" "m:{a-zA-Z}={A-Za-z}" "r:|[._-]=* r:|=*" "l:|=* r:|=*"
zmodload zsh/complist
ZDIR="$XDG_CONFIG_HOME/zsh"

# History configuration (https://zsh.sourceforge.io/Doc/Release/Options.html#History)
setopt extended_history
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt share_history

###############################################################
## KEY BINDINGS ##
###############################################################

# Make sure that the terminal is in application mode when zle is active, since
# only then values from $terminfo are valid
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
function zle-line-init() {
echoti smkx
}

function zle-line-finish() {
echoti rmkx
}

zle -N zle-line-init
zle -N zle-line-finish
fi

# [PageUp] - Up a line of history
if [[ -n "${terminfo[kpp]}" ]]; then
bindkey -M viins "${terminfo[kpp]}" up-line-or-history
bindkey -M vicmd "${terminfo[kpp]}" up-line-or-history
fi

# [PageDown] - Down a line of history
if [[ -n "${terminfo[knp]}" ]]; then
bindkey -M viins "${terminfo[knp]}" down-line-or-history
bindkey -M vicmd "${terminfo[knp]}" down-line-or-history
fi

# Start typing + [Up-Arrow] - fuzzy find history forward
if [[ -n "${terminfo[kcuu1]}" ]]; then
autoload -U up-line-or-beginning-search
zle -N up-line-or-beginning-search

bindkey -M viins "${terminfo[kcuu1]}" up-line-or-beginning-search
bindkey -M vicmd "${terminfo[kcuu1]}" up-line-or-beginning-search
fi

# Start typing + [Down-Arrow] - fuzzy find history backward
if [[ -n "${terminfo[kcud1]}" ]]; then
autoload -U down-line-or-beginning-search
zle -N down-line-or-beginning-search

bindkey -M viins "${terminfo[kcud1]}" down-line-or-beginning-search
bindkey -M vicmd "${terminfo[kcud1]}" down-line-or-beginning-search
fi

# [Home] - Go to beginning of line
if [[ -n "${terminfo[khome]}" ]]; then
bindkey -M viins "${terminfo[khome]}" beginning-of-line
bindkey -M vicmd "${terminfo[khome]}" beginning-of-line
fi

# [End] - Go to end of line
if [[ -n "${terminfo[kend]}" ]]; then
bindkey -M viins "${terminfo[kend]}" end-of-line
bindkey -M vicmd "${terminfo[kend]}" end-of-line
fi

# [Shift-Tab] - move through the completion menu backwards
if [[ -n "${terminfo[kcbt]}" ]]; then
bindkey -M viins "${terminfo[kcbt]}" reverse-menu-complete
bindkey -M vicmd "${terminfo[kcbt]}" reverse-menu-complete
fi

# [Backspace] - delete backward
bindkey -M viins "^?" backward-delete-char

# [Ctrl-Backspace] - delete whole backward-word
bindkey -M viins "^H" backward-kill-word

# [Delete] - delete forward
bindkey -M viins "^[[3~" delete-char

# [Ctrl-Delete] - delete whole forward-word
bindkey -M viins "^[[3;5~" kill-word

# [Ctrl-RightArrow] - move forward one word
bindkey -M viins "^[[1;5C" forward-word

# [Ctrl-LeftArrow] - move backward one word
bindkey -M viins "^[[1;5D" backward-word
# Modules
source "$ZDIR/misc.zsh"
source "$ZDIR/keybindings.zsh"
source "$ZDIR/aliases.zsh"
source "$ZDIR/aliases-flatpak.zsh"

# Plugins
source "$HOME/.config/zsh/plugins/zsh-autopair/autopair.zsh"
source "$HOME/.config/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh"
source "$HOME/.config/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"

###############################################################
## ALIASES ##
###############################################################

# Jump back directories
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."

# Config files
alias xconf="nvim $HOME/.Xresources"
alias lconf="nvim $XDG_CONFIG_HOME/leftwm/config.toml"
alias zconf="nvim -p \
$ZDOTDIR/.zshrc \
$ZDOTDIR/.zshenv"
alias rconf="nvim -p \
$XDG_CONFIG_HOME/ranger/rc.conf \
$XDG_CONFIG_HOME/ranger/scope.sh"
alias qconf="nvim -p $XDG_CONFIG_HOME/qtile/*.py"
alias vconf="nvim -p \
$XDG_CONFIG_HOME/nvim/init.lua \
$XDG_CONFIG_HOME/nvim/lua/options.lua \
$XDG_CONFIG_HOME/nvim/lua/plugins.lua \
$XDG_CONFIG_HOME/nvim/lua/keymaps.lua \
$XDG_CONFIG_HOME/nvim/lua/autocmds.lua \
$XDG_CONFIG_HOME/nvim/lua/functions.lua"
alias jconf="nvim -p \
$XDG_CONFIG_HOME/joshuto/joshuto.toml \
$XDG_CONFIG_HOME/joshuto/keymap.toml \
$XDG_CONFIG_HOME/joshuto/mimetype.toml"
alias xmconf="nvim -p \
$XDG_CONFIG_HOME/xmonad/xmonad.hs \
$XDG_CONFIG_HOME/xmobar/xmobar.hs"
alias dkconf="nvim -p \
$XDG_CONFIG_HOME/dk/dkrc \
$XDG_CONFIG_HOME/dk/sxhkdrc"
alias bspconf="nvim -p \
$XDG_CONFIG_HOME/bspwm/bspwmrc \
$XDG_CONFIG_HOME/sxhkd/sxhkdrc"
alias alconf="nvim -p \
$XDG_CONFIG_HOME/alacritty/alacritty.yml \
$XDG_CONFIG_HOME/alacritty/colorscheme.yml \
$XDG_CONFIG_HOME/alacritty/keybindings.yml"
alias pbconf="nvim $XDG_CONFIG_HOME/polybar/config -c 'set ft=toml'"
alias asconf="nvim ~/git-repos/dotfiles/autostart.csv"
alias kconf="sudo nvim /usr/share/X11/xkb/symbols/pc"

# git
alias gs="git status"
alias gp="git push"
alias ga="git add"
alias gaa="git add -A"
alias gau="git add -u"
alias grm="git rm -r"
alias gmv="git mv"
alias grs="git restore --staged"
alias gd="git diff --color"
alias gc="git commit"
alias gcm="git commit -m"
alias gca="git commit -a"

# ls
alias ls="lsd -l --group-dirs first"
alias la="lsd -lA --group-dirs first"
alias tree="lsd --tree --group-dirs last"

# vim
alias vim="nvim"
alias svim="sudo nvim"
alias vfz="cd /tmp/fz3temp-2/ && vim -p *.* && cd -"
alias vwiki="nvim ~/git-repos/vimwiki/notes/index.wiki"

# cp, mv, md, rm
alias cp="cp -iv"
alias mv="mv -iv"
alias md="mkdir -pv"
alias rm="trash"

# Misc
alias ps="ps axu | less"
alias top="btm -b"
alias grep="grep --color"
alias ytdl="youtube-dl"
alias pping="prettyping"
alias tlauncher="java -jar ~/Scaricati/TLauncher/TLauncher*.jar"
alias src="source ~/.zshrc && source ~/.zshenv"

# Flatpak apps
alias discord="flatpak run com.discordapp.Discord"
alias flatseal="flatpak run com.github.tchx84.Flatseal"
alias pulseeffects="flatpak run com.github.wwmm.pulseeffects"
alias android-studio="flatpak run com.google.AndroidStudio"
alias microsoft-teams="flatpak run com.microsoft.Teams"
alias obs-studio="flatpak run com.obsproject.Studio"
alias netbeans="flatpak run org.apache.netbeans"
alias telegram="flatpak run org.telegram.desktop"

###############################################################
## VI MODE ##
###############################################################

# Set vi mode keybindings
bindkey -v
bindkey -M vicmd "H" beginning-of-line
bindkey -M vicmd "L" end-of-line
bindkey -M vicmd "U" redo

# Use vim keys in tab complete menu
bindkey -M menuselect "h" vi-backward-char
bindkey -M menuselect "j" vi-down-line-or-history
bindkey -M menuselect "k" vi-up-line-or-history
bindkey -M menuselect "l" vi-forward-char

# Remove mode switching delay
KEYTIMEOUT=5

# Change cursor shape for different vi modes
function zle-keymap-select {
if [[ ${KEYMAP} == vicmd ]] || [[ $1 = "block" ]]; then
echo -ne "\e[2 q"
elif [[ ${KEYMAP} == main ]] || [[ ${KEYMAP} == viins ]] || [[ ${KEYMAP} = "" ]] || [[ $1 = "beam" ]]; then
echo -ne "\e[5 q"
fi
}

zle -N zle-keymap-select

# Use beam shape cursor for each new prompt
function precmd {
echo -ne "\e[5 q"
}

# Add dynamic title capability
function title_precmd {
print -Pn -- "\e]2;%n@%m: %~\a"
}

function title_preexec {
print -Pn -- "\e]2;%n@%m: ${(q)1}\a"
}

if [[ "$TERM" == "alacritty" ]]; then
add-zsh-hook -Uz precmd title_precmd
add-zsh-hook -Uz preexec title_preexec
fi
source "$ZDIR/plugins/zsh-autopair/autopair.zsh"
source "$ZDIR/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh"
source "$ZDIR/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh"

# Enable zoxide
eval "$(zoxide init zsh)"

# Enable starship prompt
# Enable starship
eval "$(starship init zsh)"

# Map caps to escape and shift+caps to caps_lock
setxkbmap -option caps:escape_shifted_capslock

# Autostart
pfetch
1 change: 1 addition & 0 deletions config/zsh/aliases-flatpak.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Placeholder for aliases generated by 'flatpak-alias' script
100 changes: 100 additions & 0 deletions config/zsh/aliases.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Jump back directories
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."

# Config files
alias xconf="nvim $HOME/.Xresources"
alias lconf="nvim $XDG_CONFIG_HOME/leftwm/config.toml"
alias zconf="nvim -p \
$HOME/.zshenv \
$HOME/.zshrc \
$XDG_CONFIG_HOME/zsh/misc.zsh \
$XDG_CONFIG_HOME/zsh/aliases.zsh \
$XDG_CONFIG_HOME/zsh/keybindings.zsh"
alias rconf="nvim -p \
$XDG_CONFIG_HOME/ranger/rc.conf \
$XDG_CONFIG_HOME/ranger/rifle.conf \
$XDG_CONFIG_HOME/ranger/scope.sh"
alias qconf="nvim -p $XDG_CONFIG_HOME/qtile/*.py"
alias vconf="nvim -p \
$XDG_CONFIG_HOME/nvim/init.lua \
$XDG_CONFIG_HOME/nvim/lua/options.lua \
$XDG_CONFIG_HOME/nvim/lua/plugins.lua \
$XDG_CONFIG_HOME/nvim/lua/keymaps.lua \
$XDG_CONFIG_HOME/nvim/lua/autocmds.lua \
$XDG_CONFIG_HOME/nvim/lua/functions.lua \
$XDG_CONFIG_HOME/nvim/colors/monokai.lua"
alias jconf="nvim -p $XDG_CONFIG_HOME/joshuto/*.toml"
alias xmconf="nvim -p \
$XDG_CONFIG_HOME/xmonad/xmonad.hs \
$XDG_CONFIG_HOME/xmobar/xmobar.hs"
alias dkconf="nvim -p \
$XDG_CONFIG_HOME/dk/dkrc \
$XDG_CONFIG_HOME/dk/sxhkdrc"
alias bspconf="nvim -p \
$XDG_CONFIG_HOME/bspwm/bspwmrc \
$XDG_CONFIG_HOME/sxhkd/sxhkdrc"
alias alconf="nvim -p \
$XDG_CONFIG_HOME/alacritty/alacritty.yml \
$XDG_CONFIG_HOME/alacritty/colorscheme.yml \
$XDG_CONFIG_HOME/alacritty/keybindings.yml"
alias pbconf="nvim $XDG_CONFIG_HOME/polybar/config -c 'set ft=toml'"
alias asconf="nvim ~/git-repos/dotfiles/autostart.csv"
alias kconf="sudo nvim /usr/share/X11/xkb/symbols/pc"

# git
alias gs="git status"
alias gS="git stash"
alias gp="git push"
alias gP="git pull"
alias ga="git add"
alias gA="git add -A"
alias gau="git add -u"
alias grm="git rm -r"
alias gmv="git mv"
alias gr="git restore"
alias grs="git restore --staged"
alias gd="git diff"
alias gds="git diff --staged"
alias gc="git commit"
alias gcm="git commit -m"
alias gca="git commit -a"
alias gb="git branch"
alias gck="git checkout"

# ls
alias ls="lsd -l"
alias la="lsd -lA"
alias tree="lsd --tree --group-dirs last"

# cp, mv, md, rm
alias cp="cp -v"
alias mv="mv -v"
alias md="mkdir -pv"
alias rm="trash"

# Neovim
alias v="nvim -p"
alias vc="nvim --clean"
alias vs="nvim .session.lua"
alias sv="sudo nvim"

# Docker
alias d="docker"
alias dc="docker compose"
alias di="docker image"
alias dn="docker network"
alias dv="docker volume"

# Misc
alias se="sudoedit"
alias ps="ps axu | less"
alias btm="btm -b"
alias grep="grep --color"
alias ytdl="yt-dlp"
alias cups="xdg-open localhost:631"
alias pping="prettyping"
alias src="source ~/.zshrc && source ~/.zshenv"
Loading

0 comments on commit 6d0941b

Please sign in to comment.