zsh: follow-up for ff1f227e0e
This commit is contained in:
parent
ff1f227e0e
commit
8e948d4495
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env zsh
|
||||
# ~/.config/zsh_confs/01_history: zsh history file
|
||||
|
||||
# export variables
|
||||
export HISTFILE=$HOME/.sh_history
|
||||
export HISTFILESIZE=10000
|
||||
export HISTSIZE=10000
|
||||
export SAVEHIST=10000
|
||||
|
||||
# refer to `https://zsh.sourceforge.io/Doc/Release/Options.html#History`
|
||||
setopt APPEND_HISTORY
|
||||
setopt BANG_HIST
|
||||
setopt HIST_EXPIRE_DUPS_FIRST
|
||||
setopt HIST_FIND_NO_DUPS
|
||||
setopt HIST_IGNORE_ALL_DUPS
|
||||
setopt HIST_IGNORE_DUPS
|
||||
setopt HIST_IGNORE_SPACE
|
||||
setopt HIST_NO_FUNCTIONS
|
||||
setopt HIST_SAVE_BY_COPY
|
||||
setopt INC_APPEND_HISTORY
|
|
@ -0,0 +1,229 @@
|
|||
#!/usr/bin/env zsh
|
||||
# ~/.config/zsh_confs/XX_aliases: my [zsh] shell aliases
|
||||
|
||||
# hostname
|
||||
MACHINE_HOSTNAME=$(cat /etc/hostname)
|
||||
|
||||
# export everything first
|
||||
export TERM="xterm-256color"
|
||||
export TIMEFMT=$'\nJob\t%J\n\nCPU\t%P\nuser\t%U\nsystem\t%S\ntotal\t%E'
|
||||
export LANG=en_IN.UTF-8
|
||||
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
export EDITOR=/usr/bin/nvim
|
||||
export SYSTEMD_EDITOR=/usr/bin/nvim
|
||||
|
||||
if [[ "$MACHINE_HOSTNAME" == "flameboi" ]]; then
|
||||
export LESS=SRX
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
export EDITOR=/usr/local/bin/nvim
|
||||
fi
|
||||
|
||||
# add dir to PATH if present
|
||||
# precedence from top (lowest) to bottom (highest)
|
||||
[[ -d "$HOME/.local/bin" ]] && export PATH=$HOME/.local/bin:$PATH
|
||||
[[ -d "$HOME/.cargo/bin" ]] && export PATH=$HOME/.cargo/bin:$PATH
|
||||
[[ -d /usr/local/sbin ]] && export PATH=/usr/local/sbin:$PATH
|
||||
[[ -d /usr/sbin ]] && export PATH=/usr/sbin:$PATH
|
||||
[[ -d /sbin ]] && export PATH=/sbin:$PATH
|
||||
[[ -d /usr/local/bin ]] && export PATH=/usr/local/bin:$PATH
|
||||
[[ -d /usr/bin ]] && export PATH=/usr/bin:$PATH
|
||||
[[ -d /bin ]] && export PATH=/bin:$PATH
|
||||
if command -v rustup > /dev/null; then
|
||||
RUSTUP_TRIPLET=$(rustup show active-toolchain | awk '{print $1}')
|
||||
RUSTUP_PATH="$HOME/.rustup/toolchains/$RUSTUP_TRIPLET/bin"
|
||||
[[ -d "$RUSTUP_PATH" ]] && export PATH=$RUSTUP_PATH:$PATH
|
||||
# rust-analyzer is in $RUSTUP_PATH instead of $HOME/.cargo/bin :(
|
||||
# rust-analyzer needs to be in $PATH for good Rust support in Neovim
|
||||
fi
|
||||
typeset -U PATH
|
||||
|
||||
# common aliases
|
||||
alias flushSSH="ssh-keygen -R"
|
||||
alias mtr='mtr --show-ips --displaymode 0 -o "LDR AGJMXI"'
|
||||
alias update="source $HOME/.zshrc" # other files are sourced automatically
|
||||
alias custcp="rsync --verbose --recursive --size-only --human-readable --progress --stats --itemize-changes"
|
||||
alias pysort="$HOME/.scripts/other/sort.py"
|
||||
alias download="aria2c -x 16 -k 1M --file-allocation=none --continue=false"
|
||||
alias vim="nvim"
|
||||
alias showsslvalidity="~/.scripts/common-scripts/domain_ssl_validity.sh"
|
||||
alias ytdown="yt-dlp --config-location $HOME/.config/yt-dlp/norm_config --external-downloader aria2c"
|
||||
alias playdl="yt-dlp --config-location $HOME/.config/yt-dlp/plst_config --external-downloader aria2c"
|
||||
alias ytslow="yt-dlp --config-location $HOME/.config/yt-dlp/norm_config --no-part --concurrent-fragments 1 --limit-rate 4M"
|
||||
alias gcommitm="git commit -m"
|
||||
alias sudo="sudo "
|
||||
|
||||
if command -v batcat > /dev/null; then
|
||||
alias bat="batcat"
|
||||
fi
|
||||
|
||||
if command -v doas > /dev/null; then
|
||||
unalias sudo
|
||||
alias sudo="doas"
|
||||
fi
|
||||
|
||||
# OS/hostname specific aliases
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# common ls aliases
|
||||
alias l="ls --group-directories-first --color=auto -v"
|
||||
alias ll="ls --group-directories-first --color=auto -1lv"
|
||||
alias la="ls --group-directories-first --color=auto -1Av"
|
||||
alias lo="ls --group-directories-first --color=auto -1v"
|
||||
alias llh="ls --group-directories-first --color=auto -1hlv"
|
||||
alias lah="ls --group-directories-first --color=auto -1Ahlv"
|
||||
alias ldt="ls --group-directories-first --color=auto -1Altv"
|
||||
|
||||
# common grep aliases
|
||||
alias grep="grep --color=auto"
|
||||
alias greplv="grep --color=auto -lv"
|
||||
alias grepli="grep --color=auto -li"
|
||||
alias grepv="grep --color=auto -v"
|
||||
alias grepi="grep --color=auto -i"
|
||||
|
||||
# ssh related aliases
|
||||
alias flameboi="ssh pratham@flameboi.lan"
|
||||
alias sentinel="ssh ubuntu@sentinel.lan"
|
||||
alias bluefeds="ssh pratham@bluefeds.lan"
|
||||
|
||||
# aliases for flatpak
|
||||
alias flatpakupdates="flatpak remote-ls --updates flathub"
|
||||
alias flatpakautoremove="flatpak remove --unused --delete-data"
|
||||
# generate `flatpak run <name>`
|
||||
if command -v flatpak > /dev/null; then
|
||||
# Get a list of flatpak applications in the reverse domain name format
|
||||
readarray -t ids < <(flatpak list --app --columns=application)
|
||||
for id in "${ids[@]}"; do
|
||||
|
||||
# Take everything past the last dot (the name)
|
||||
name="${id##*.}"
|
||||
# Make it lowercase to approximate binary name
|
||||
binary="${name,,}"
|
||||
|
||||
# If there is not already a command at that name
|
||||
if ! command -v "${binary}" > /dev/null; then
|
||||
|
||||
# Create an alias that runs the flatpak
|
||||
alias "$binary=flatpak run \"$id\""
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# other common aliases
|
||||
alias tmux="/usr/bin/tmux -f $HOME/.config/tmux/tmux.conf"
|
||||
alias ping="ping -W 0.1 -O"
|
||||
alias pmount="mount -o gid=pratham,uid=pratham"
|
||||
alias mpv="/usr/bin/mpv --geometry=60% --vo=gpu --hwdec=vaapi"
|
||||
alias pbcopy="xsel --clipboard --input"
|
||||
|
||||
if [[ "$MACHINE_HOSTNAME" == "flameboi" ]]; then
|
||||
alias drivetemp="sudo hdparm -CH /dev/sda /dev/sdb /dev/sdc /dev/sdd"
|
||||
|
||||
# aliases useful when using a WM
|
||||
alias suslock="$HOME/.config/polybar/mods/module_suspend_script.sh"
|
||||
alias gnomecontrolcenter="XDG_CURRENT_DESKTOP=GNOME gnome-control-center"
|
||||
alias gnomecc="XDG_CURRENT_DESKTOP=GNOME gnome-control-center"
|
||||
|
||||
# chown everything in /heathen_disk
|
||||
owndisk() {
|
||||
OWNDIR=/heathen_disk
|
||||
sudo chmod 774 -R "$OWNDIR"
|
||||
sudo /usr/bin/chown pratham:pratham -R "$OWNDIR"
|
||||
find "$OWNDIR" -type f -exec chmod 660 {} \;
|
||||
find "$OWNDIR" -type f -name "._*" -exec rm -iv {} \;
|
||||
find "$OWNDIR" -type f -name "*.DS_Store" -exec rm -iv {} \;
|
||||
}
|
||||
|
||||
elif [[ "$MACHINE_HOSTNAME" == "bluefeds" ]]; then
|
||||
alias clear="/usr/bin/clear && printf '\e[3J'"
|
||||
alias drivetemp="sudo hdparm -CH /dev/sda /dev/sdb"
|
||||
|
||||
# aliases for container management
|
||||
ALL_CONTAINERS=("container-caddy-vishwambhar.service" \
|
||||
"container-gitea-govinda.service" \
|
||||
"container-gitea-chitragupta.service" \
|
||||
"container-hugo-vaikunthnatham.service" \
|
||||
"container-nextcloud-govinda.service" \
|
||||
"container-nextcloud-chitragupta.service" \
|
||||
"container-hugo-mahayogi.service" \
|
||||
"container-gotify-akashvani.service" \
|
||||
"container-transmission-raadhe.service" \
|
||||
)
|
||||
alias containerupdate="podman auto-update --dry-run | grep -v 'false'"
|
||||
alias containerpruneimages="podman system prune -a"
|
||||
|
||||
containerdisableall() {
|
||||
for INDV_CONTAINER in "${ALL_CONTAINERS[@]}"; do
|
||||
systemctl --user disable "$INDV_CONTAINER"
|
||||
done
|
||||
}
|
||||
|
||||
containerenableall() {
|
||||
for INDV_CONTAINER in "${ALL_CONTAINERS[@]}"; do
|
||||
systemctl --user enable "$INDV_CONTAINER"
|
||||
done
|
||||
}
|
||||
|
||||
containerstopall() {
|
||||
for INDV_CONTAINER in "${ALL_CONTAINERS[@]}"; do
|
||||
if [[ $(systemctl --user is-enabled "$INDV_CONTAINER") -eq 0 ]]; then
|
||||
systemctl --user is-active --quiet service "$INDV_CONTAINER" && systemctl --user stop "$INDV_CONTAINER" && echo "$INDV_CONTAINER: stopped"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
containerstats() {
|
||||
systemctl --user status "${ALL_CONTAINERS[@]}" | grep '(running) since\|●\|ago'
|
||||
TOTAL_RUNNING=$(podman ps --format '{{.Names}}' | wc -l)
|
||||
TOTAL_CONTAINERS=$(podman container list -a --format '{{.Names}}' | wc -l)
|
||||
|
||||
echo -e "Running:\t${TOTAL_RUNNING}/9"
|
||||
echo -e "Containers:\t${TOTAL_CONTAINERS}/9"
|
||||
}
|
||||
|
||||
# rebuild ZFS DKMS automatically/manually
|
||||
rebuildzfs() {
|
||||
# equivalent of `uname -r` but for _all_ kernels that are installed
|
||||
ALL_KERNELS=($(sudo dnf info kernel | grep Source | awk '{print $3}' | sed "s/kernel-//g" | sed "s/src.rpm/$(uname -m)/g"))
|
||||
# get the latest version of ZFS (`zfs/2.1.7`)
|
||||
LATEST_ZFS_VER=$(git ls-remote --refs --tags https://github.com/openzfs/zfs | cut --delimiter='/' --fields=3 | sort --version-sort | tail --lines=2 | head --lines=1 | sed "s/-/\//g")
|
||||
|
||||
for KERNEL in "${ALL_KERNELS[@]}"; do
|
||||
if [[ $(sudo dkms status -k ${KERNEL} | grep "$LATEST_ZFS_VER" | grep "installed") -eq 0 ]]; then
|
||||
echo -ne "ZFS is installed for $KERNEL. You may REINSTALL it using the following command:\nsudo dkms install ${LATEST_ZFS_VER} -k ${KERNEL}\n\n"
|
||||
else
|
||||
echo "ZFS is NOT installed for $KERNEL. Building and intalling..."
|
||||
sudo dkms install "${LATEST_ZFS_VER}" -k "${KERNEL}"
|
||||
echo -ne "\n--------------------------------------------------------------------------------\n"
|
||||
fi
|
||||
done
|
||||
}
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
|
||||
# aliases for ls
|
||||
alias l="/usr/local/bin/gls --group-directories-first --color=auto -v"
|
||||
alias ll="/usr/local/bin/gls --group-directories-first --color=auto -1lv"
|
||||
alias la="/usr/local/bin/gls --group-directories-first --color=auto -1Av"
|
||||
alias lo="/usr/local/bin/gls --group-directories-first --color=auto -1v"
|
||||
alias llh="/usr/local/bin/gls --group-directories-first --color=auto -1hlv"
|
||||
alias lah="/usr/local/bin/gls --group-directories-first --color=auto -1Ahlv"
|
||||
alias ldt="/usr/local/bin/gls --group-directories-first --color=auto -1Altv"
|
||||
|
||||
# aliases for grep
|
||||
alias grep="/usr/local/bin/ggrep --color=auto"
|
||||
alias greplv="/usr/local/bin/ggrep --color=auto -lv"
|
||||
alias grepli="/usr/local/bin/ggrep --color=auto -li"
|
||||
alias grepv="/usr/local/bin/ggrep --color=auto -v"
|
||||
alias grepi="/usr/local/bin/ggrep --color=auto -i"
|
||||
|
||||
# other aliases
|
||||
alias xargs="/usr/local/opt/findutils/libexec/gnubin/xargs"
|
||||
alias tmux="/usr/local/bin/tmux -f $HOME/.config/tmux/tmux.conf"
|
||||
alias clear="/usr/bin/clear && printf '\e[3J'"
|
||||
alias ktb="sudo pkill TouchBarServer; killall ControlStrip"
|
||||
alias mpv="/usr/local/bin/mpv --vo=libmpv"
|
||||
fi
|
||||
|
||||
# source functions
|
||||
source $HOME/.config/zsh_confs/21_alias_funcs
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env zsh
|
||||
# ~/.config/zsh_confs/XX_alias_funcs: my alias functions
|
||||
|
||||
towebp() {
|
||||
cwebp -q 80 "$1" -o "$1".webp
|
||||
}
|
||||
|
||||
togif() {
|
||||
ffmpeg -i "$1" -pix_fmt rgb24 "$1".gif
|
||||
}
|
||||
|
||||
gitaddpush() {
|
||||
git ls-remote --quiet --exit-code origin >/dev/null 2>&1
|
||||
if [[ $? -ne 0 ]]; then
|
||||
git remote add origin "$1"
|
||||
fi
|
||||
git remote set-url --add --push origin "$1"
|
||||
}
|
||||
|
||||
gitaddpull() {
|
||||
git ls-remote --quiet --exit-code origin >/dev/null 2>&1
|
||||
if [[ $? -ne 0 ]]; then
|
||||
git remote add origin "$1"
|
||||
fi
|
||||
git remote set-url --add --pull origin "$1"
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env zsh
|
||||
# ~/.config/zsh_confs/XX_syntax_highlight: zsh file for syntax highlighting
|
||||
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
|
||||
MACHINE_HOSTNAME=$(cat /etc/hostname)
|
||||
|
||||
if [[ "$MACHINE_HOSTNAME" == "flameboi" ]]; then
|
||||
ZSH_SYNTAX_HIGHLIGHT_PATH="/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
|
||||
elif [[ "$MACHINE_HOSTNAME" == "sentinel" || "$MACHINE_HOSTNAME" == "bluefeds" ]]; then
|
||||
ZSH_SYNTAX_HIGHLIGHT_PATH="/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
|
||||
fi
|
||||
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
ZSH_SYNTAX_HIGHLIGHT_PATH="/usr/local/opt/zsh-fast-syntax-highlighting/share/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh"
|
||||
fi
|
||||
|
||||
source ZSH_SYNTAX_HIGHLIGHT_PATH
|
122
.zshrc
122
.zshrc
|
@ -1,108 +1,62 @@
|
|||
# ~/.zshrc: executed by zsh(1) for non-login shells
|
||||
|
||||
# if not running interactively, do not do anything
|
||||
# if not running interactively, don't do anything
|
||||
case $- in
|
||||
*i*) ;;
|
||||
*) return;;
|
||||
esac
|
||||
|
||||
# load ~/.zsh_aliases if it exists
|
||||
if [[ -f "$HOME/.zsh_aliases" ]]; then
|
||||
source $HOME/.zsh_aliases
|
||||
fi
|
||||
# for using comments in interactive shell
|
||||
setopt INTERACTIVECOMMENTS
|
||||
|
||||
# load keybinds if they exist
|
||||
# directory where most of my zsh files are stored
|
||||
ZSH_CONFS_DIRECTORY="$HOME/.config/zsh_confs"
|
||||
|
||||
# load options related to history
|
||||
source $ZSH_CONFS_DIRECTORY/10_history
|
||||
|
||||
# keep the space after tab completion
|
||||
ZLE_REMOVE_SUFFIX_CHARS=""
|
||||
|
||||
# key-bindings
|
||||
if [[ -f "$HOME/.zkbd/$TERM" ]]; then
|
||||
source $HOME/.zkbd/$TERM
|
||||
|
||||
[[ -n ${key[Home]} ]] && bindkey "${key[Home]}" beginning-of-line
|
||||
[[ -n ${key[End]} ]] && bindkey "${key[End]}" end-of-line
|
||||
[[ -n ${key[Delete]} ]] && bindkey "${key[Delete]}" delete-char
|
||||
fi
|
||||
|
||||
export TERM="xterm-256color"
|
||||
#bindkey "^[[H" beginning-of-line
|
||||
#bindkey "^[[F" end-of-line
|
||||
#bindkey "^[[3~" delete-char
|
||||
|
||||
# enable ZSH history
|
||||
export HISTFILE=$HOME/.sh_history
|
||||
export HISTFILESIZE=1000000000
|
||||
export HISTSIZE=1000000000
|
||||
export SAVEHIST=1000000000
|
||||
# refer to https://linux.die.net/man/1/zshoptions
|
||||
setopt APPEND_HISTORY
|
||||
setopt HIST_IGNORE_ALL_DUPS
|
||||
setopt HIST_IGNORE_DUPS
|
||||
setopt HIST_IGNORE_SPACE
|
||||
setopt HIST_SAVE_BY_COPY
|
||||
setopt INC_APPEND_HISTORY
|
||||
|
||||
# keep the space after tab auto-completion
|
||||
ZLE_REMOVE_SUFFIX_CHARS=""
|
||||
|
||||
# use Ctrl+left and Ctrl+right to jump a word back and forth respectively
|
||||
bindkey "^[[1;5C" forward-word
|
||||
bindkey "^[[1;5D" backward-word
|
||||
bindkey '^i' expand-or-complete-prefix
|
||||
|
||||
# for using comments in interactive shell
|
||||
setopt INTERACTIVECOMMENTS
|
||||
|
||||
# prompt
|
||||
PROMPT=$'\n%F{11}─┬─[%f %F{5}%y %f%F{white}%? %D %*%f %F{11}]%f
|
||||
%F{11} ├─[%f %F{red}%m:%f %F{white}%n%f %F{8}▶%f %F{cyan}%/%f %F{11}]%f
|
||||
%F{11} ╰─>%F{11}%f '
|
||||
|
||||
# common stuff...
|
||||
MACHINE_HOSTNAME=$(cat /etc/hostname)
|
||||
|
||||
# common stuff for Linux
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
|
||||
# syntax highlighting
|
||||
ZSH_SYNTAX_HIGH="/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
|
||||
if [[ -f "$ZSH_SYNTAX_HIGH" ]]; then
|
||||
source $ZSH_SYNTAX_HIGH
|
||||
fi
|
||||
if [[ "$MACHINE_HOSTNAME" == "flameboi" ]]; then
|
||||
# The following lines were added by compinstall
|
||||
zstyle ':completion:*' completer _alternative _approximate _arguments _complete _expand _ignored
|
||||
zstyle ':completion:*' group-name ''
|
||||
zstyle compinstall filename "$HOME/.zshrc"
|
||||
|
||||
export LANG=en_IN.UTF-8
|
||||
|
||||
source /etc/os-release
|
||||
MACHINE_HOSTNAME=$(cat /etc/hostname)
|
||||
|
||||
if [[ "$NAME" = "Pop!_OS" && "$MACHINE_HOSTNAME" == "flameboi" ]]; then
|
||||
# The following lines were added by compinstall
|
||||
zstyle ':completion:*' completer _expand _complete _ignored
|
||||
zstyle ':completion:*' group-name ''
|
||||
zstyle :compinstall filename "$HOME/.zshrc"
|
||||
|
||||
autoload -Uz compinit
|
||||
compinit
|
||||
# End of lines added by compinstall
|
||||
fi
|
||||
|
||||
|
||||
if [[ "$NAME" = "Fedora Linux" && "$MACHINE_HOSTNAME" == "bluefeds" ]]; then
|
||||
# use bigger fonts in tty
|
||||
case $(tty) in
|
||||
(/dev/tty[0-9]) setfont /usr/share/consolefonts/Lat2-Terminus28x14.psf.gz;;
|
||||
(/dev/pts/[0-9]) ;;
|
||||
esac
|
||||
|
||||
fi
|
||||
|
||||
|
||||
if [[ "$NAME" = "Ubuntu" && "$MACHINE_HOSTNAME" == "sentinel" ]]; then
|
||||
# use bigger fonts in tty
|
||||
case $(tty) in
|
||||
(/dev/tty[0-9]) setfont /usr/share/consolefonts/Lat2-Terminus28x14.psf.gz;;
|
||||
(/dev/pts/[0-9]) ;;
|
||||
esac
|
||||
|
||||
fi
|
||||
|
||||
# stuff for macOS
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
|
||||
# syntax highlighting
|
||||
ZSH_SYNTAX_HIGH="/usr/local/opt/zsh-fast-syntax-highlighting/share/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh"
|
||||
if [[ -f "$ZSH_SYNTAX_HIGH" ]]; then
|
||||
source $ZSH_SYNTAX_HIGH
|
||||
fi
|
||||
autuload -Uz compinit
|
||||
compinit
|
||||
# End of lines added by compinstall
|
||||
else if [[ "$MACHINE_HOSTNAME" == "bluefeds" || "$MACHINE_HOSTNAME" == "sentinel" ]]; then
|
||||
# use bigger fonts on the console
|
||||
case $(tty) in
|
||||
(/dev/tty[0-9]) setfont /usr/share/consolefonts/Lat2-Terminus28x14.psf.gz;;
|
||||
(/dev/pts[0-9]) ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# source aliases
|
||||
source $ZSH_CONFS_DIRECTORY/20_aliases
|
||||
|
||||
# source zsh syntax highlighting
|
||||
source $ZSH_CONFS_DIRECTORY/90_syntax_highlight
|
||||
|
|
Loading…
Reference in New Issue