Last active
July 23, 2025 06:26
-
-
Save dardo82/a866c7f10729118f5400bc3f4c693370 to your computer and use it in GitHub Desktop.
ZSH configs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# ZSH conf | |
# Set OMZ options. | |
export ZSH="$HOME/.oh-my-zsh" | |
zstyle ':omz:update' mode reminder | |
# Set history options. | |
export HISTFILE="$HOME/.zsh_history" | |
export HISTSIZE="$[2**32]" | |
export SAVEHIST="$[2**32]" | |
setopt EXTENDED_HISTORY | |
setopt HIST_IGNORE_DUPS | |
setopt SHARE_HISTORY | |
setopt HIST_VERIFY | |
# Set shell options. | |
setopt NOTIFY | |
setopt EXTENDED_GLOB | |
setopt MAGIC_EQUAL_SUBST | |
setopt NUMERIC_GLOB_SORT | |
# Set completion options. | |
export CASE_SENSITIVE="true" | |
export COMPLETION_WAITING_DOTS="true" | |
zstyle ':completion:*:*:*:*:*' menu select | |
# Set plugins. | |
plugins=(zsh-autosuggestions zsh-syntax-highlighting) | |
# Set keys bindings. | |
export WORDCHARS="" | |
bindkey "^[[1;5C" forward-word | |
bindkey "^[[1;5D" backward-word | |
bindkey "^[[1;3C" vi-forward-blank-word | |
bindkey "^[[1;3D" vi-backward-blank-word | |
bindkey "^U" backward-kill-line | |
autoload backward-kill-word-match | |
zle -N backward-kill-space-word backward-kill-word-match | |
zstyle :zle:backward-kill-space-word word-style space | |
bindkey "^[w" backward-kill-space-word | |
bindkey "^[[3~" delete-char | |
bindkey " " magic-space | |
bindkey "^['" insert-composed-char | |
# Set default programs. | |
export LESSOPEN="|~/.lessfilter %s" | |
export PYGMENTIZE_STYLE="default" | |
export BROWSER="google-chrome" | |
export EDITOR="vim" | |
# Set language. | |
export LC_ALL="C.utf8" | |
# Set display. | |
export DISPLAY=":0" | |
# Set pipx directories. | |
export PIPX_BIN_DIR="/usr/local/bin/" | |
export PIPX_HOME="/usr/local/pipx/" | |
# Set go directories. | |
export GOPATH="/usr/local" | |
# Enable colored commands. | |
if [ -x $(which gdircolors) ]; then | |
test -r ~/.dircolors && eval "$(gdircolors -b ~/.dircolors)" || eval "$(gdircolors -b)" | |
alias cal='ccal' | |
alias diff='colordiff' | |
alias ls='ls --color' | |
alias grep='grep --color' | |
alias less='less -R --use-color' | |
export LESS_TERMCAP_mb=$'\E[1;31m' # begin blink | |
export LESS_TERMCAP_md=$'\E[1;36m' # begin bold | |
export LESS_TERMCAP_me=$'\E[0m' # reset bold/blink | |
export LESS_TERMCAP_so=$'\E[01;33m' # begin reverse video | |
export LESS_TERMCAP_se=$'\E[0m' # reset reverse video | |
export LESS_TERMCAP_us=$'\E[1;32m' # begin underline | |
export LESS_TERMCAP_ue=$'\E[0m' # reset underline | |
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" | |
fi | |
# Set command prompt. | |
case "$TERM" in | |
linux|*color*) PC=1;; | |
esac | |
if [ $PC ]; then precmd() { | |
TL_PS1="%b%F{%(#.blue.green)}┌(%B%F{%(#.red.blue)}${USER%@*}%(#.:.@)$HOST%b%F{%(#.blue.green)})─[%B%F{reset}%~%b%F{%(#.blue.green)}]" | |
TR_PS1="%b%F{%(#.blue.green)}[%B%F{reset}%T%b%F{%(#.blue.green)}]─(%B%F{%(#.red.blue)}%D{%d/%m}%b%F{%(#.blue.green)})" | |
BL_PS1="%b%F{%(#.blue.green)}└>%B%F{%(#.red.blue)}$%b%F{reset} " | |
BR_PS1=$'%(?.. %? %B%F{red}⨯%b%F{reset})%(1j. %j %B%F{yellow}⚙%b%F{reset}.)' | |
TR_PS1_L="${#${(%)TR_PS1}//$'\e'\[[0-9]##m}" | |
TL_PS1_L="${#${(%)TL_PS1}//$'\e'\[[0-9]##m}" | |
PAD_PS1="${(r:$[COLUMNS-$TL_PS1_L-$TR_PS1_L-2]::─:)}" | |
PROMPT="$TL_PS1─$PAD_PS1─$TR_PS1"$'\n'"$BL_PS1" | |
RPROMPT="${(%)BR_PS1}" | |
} fi | |
# Define aliases. | |
alias hbu="home-backup" | |
alias hl='highlight -O ansi' | |
alias sued="sudo $EDITOR" | |
alias rb="sudo reboot" | |
alias gh-sr="gh search repos -L 1 -q '.[].fullName' --json fullName" | |
alias psn="port search --name" | |
alias spi="sudo port install" | |
alias tmu-md="tmutil machinedirectory" | |
alias beep="sudo sh -c \"echo '\a' > /dev/console\"" | |
# Define functions. | |
mpv-yt-lw() {ID=$(yt-dlp -v --get-id --playlist-items ${1:-1} --cookies-from-browser chrome+gnomekeyring :ythistory); mpv -v --ytdl-format=135+140 ytdl://$ID} | |
lsl-gist() {gh gist list -L 100 | gawk -v RE=$1 '{if ($0~RE) {print $1; exit}}'} | |
ull-gist() {gh gist edit -a $1 $(lsl-gist $2)} | |
catl-gist() {gh gist view $(lsl-gist $1)} | |
viml-gist() {gh gist edit $(lsl-gist $1)} | |
dll-gist() {gh gist clone $(lsl-gist $1)} | |
dl-gist-rev() {curl -s $(curl -s $(gh api /gists/$(lsl-gist $1)/commits | jq -r '.[].url' | sed -n ${3:-1}p) | jq -r --arg name $2 '.files|.[$name].raw_url')} | |
acmes() {fc -l -n -${2:-0} >> $1; ${EDITOR:-vi} $1} | |
acmes-shrc() {acmes $HOME/.${SHELL/*\/}rc ${1:-0}} | |
pip-dir() {echo $(pip show $1 | awk -v FS='[: ]' '/Loc/{print $3}')/${1//-/_}} | |
gh-url() {GHUC="githubusercontent"; RAW="https://raw.$GHUC.com"; echo $RAW/$1/master/$2} | |
gh-ls() {OPT="recursive=1"; REPO="$1"; BRANCH=$(gh api "repos/$REPO" --jq ".default_branch"); \ | |
gh api -q ".tree[].path" "repos/$REPO/git/trees/$BRANCH?$OPT" | grep $2} | |
gh-dl() {REPO=$(gh-sr $1); curl -O -w %{url} $(gh-url $REPO $(gh-ls $REPO $2))} | |
ports () { | |
SERVICES=(${(f)"$(</etc/services)"}); MATCHES=(${(M)SERVICES:#*$1*}) | |
for i in {1..$#LDAP}; do | |
PORTS=(${(ps:\t:)MATCHES[$i]}); PNUMS[$i]=${PORTS[2]%/*} | |
done; echo ${(u)PNUMS}} | |
epoch() {date -d "@ $1" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
# ZSH configuration | |
# Set shell options. | |
export SH="${SHELL##*/}" | |
export SHRC="$HOME/.${SH}rc" | |
export CORRECT_IGNORE="_*" | |
export CORRECT_IGNORE_FILE=".*" | |
setopt NOTIFY | |
setopt CORRECT | |
setopt RC_EXPAND_PARAM | |
setopt SH_FILE_EXPANSION | |
setopt NO_CASE_GLOB | |
setopt EXTENDED_GLOB | |
setopt NUMERIC_GLOB_SORT | |
setopt MAGIC_EQUAL_SUBST | |
setopt CSH_NULL_GLOB | |
setopt AUTO_CD | |
setopt AUTO_PUSHD | |
setopt PUSHD_MINUS | |
setopt PUSHD_IGNORE_DUPS | |
# Set history options. | |
local H="history" | |
export HF="$HOME/.${SH}_$H" | |
export HISTFILE="$HF" | |
export HISTSIZE="$[2**16]" | |
export SAVEHIST="$[2**15]" | |
setopt INC_APPEND_HISTORY | |
setopt HIST_IGNORE_DUPS | |
setopt EXTENDED_HISTORY | |
setopt SHARE_HISTORY | |
setopt HIST_VERIFY | |
# Set PATH var. | |
[[ -d "$HOME/.local/bin" ]] && \ | |
export PATH="$HOME/.local/bin:$PATH" | |
[[ -d "/opt/google-cloud-cli/bin" ]] && \ | |
export PATH="/opt/google-cloud-cli/bin:$PATH" | |
# Set PYENV vars and dirs. | |
export PYENV_ROOT="$HOME/.pyenv" | |
[[ -d $PYENV_ROOT/bin ]] \ | |
&& export PATH="$PYENV_ROOT/bin:$PATH" | |
eval "$(pyenv init - zsh)" | |
# Set PIP and PIPX dirs. | |
export PYVER="${${(L)$(python -V)/ }%.*}" | |
export PIP_DIR="/usr/lib/$PYVER/site-packages" | |
export PIPX_BIN_DIR="/usr/local/bin" | |
export PIPX_HOME="/usr/local/pipx" | |
# Set GO dir. | |
export GOPATH="/usr/local" | |
# Set default programs. | |
export PAGER="nvimpager -a" | |
export EDITOR="nvim" | |
export BROWSER="w3m" | |
# Set misc vars. | |
local RSF="--remove-source-files" | |
local NAWW="_NET_ACTIVE_WINDOW(WINDOW):" | |
export TZ="$(</etc/timezone)" | |
export EMAIL="[email protected]" | |
export G="google" | |
export GH="github" | |
export SOF="stackoverflow" | |
export WORDSFILE="/usr/share/dict/words" | |
export DOC_DIR="/usr/share/doc" | |
export FUNC_DIR="/usr/share/zsh/functions" | |
export VIM_DIR="/usr/share/vim/vimfiles" | |
export NVIM_DIR="/usr/share/nvim/runtime" | |
export ICON_DIR="/usr/share/icons/hicolor/128x128/apps" | |
export BG_DIR="/usr/share/backgrounds" | |
export PKG_DIR="/var/cache/pacman/pkg" | |
export PARU_DIR="$HOME/.cache/paru/clone" | |
export PYPKG_DIR="/usr/lib/${${${(L)$(python -V)}%.*}/ }/site-packages" | |
export LCONF_DIR="Development/Casa/Codice/Sistema/Linux/Config" | |
export TRASH_DIR="$HOME/.local/share/Trash" | |
export CHROME_CONFIG_HOME="$HOME/.local/share" | |
export GEMINI_API_KEY=$(<$HOME/.gemini_api_key) | |
export SUDO_ASKPASS="/usr/bin/askpass-bemenu" | |
export BEMENU_BACKEND="curses" | |
export IP=$(ip -br addr | awk '$2=="UP"{print $3}') | |
export WIFI=$(nmcli connection show --active | awk '/wifi/{print $1}') | |
# Set completion options. | |
export CASE_SENSITIVE="true" | |
export COMPLETION_WAITING_DOTS="true" | |
autoload -Uz compinit; compinit | |
autoload -U +X bashcompinit && bashcompinit | |
zstyle ':completion:*' rehash true | |
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' | |
zstyle ':completion:*' completer _expand _complete _ignored _approximate | |
zstyle ':completion:*' menu select | |
zstyle ':completion:*:descriptions' format '%U%F{cyan}%d%f%u' | |
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s' | |
zstyle ':completion:*' use-cache on | |
zstyle ':completion:*' accept-exact '*(N)' | |
zstyle ':completion:*' cache-path ~/.cache/zcache | |
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" | |
# Get better help. | |
RH="run-help"; [[ $(whence -w $RH) == "$RH: alias" ]] && unalias $RH | |
export HELPDIR="/usr/share/zsh/$ZSH_VERSION/help" | |
export HELPPAGER="bat -p -l help" | |
autoload $RH | |
autoload $RH-sudo | |
autoload $RH-git | |
# Load misc functions. | |
autoload zargs | |
autoload zed | |
# Enable plugins. | |
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh | |
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(brackets) | |
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh | |
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=yellow,bold" | |
ZSH_AUTOSUGGEST_STRATEGY=(history match_prev_cmd) | |
ZSH_AUTOSUGGEST_IGNORE_WIDGETS+=(backward-kill-space-word backward-kill-word kill-word autopair-\*) | |
source /usr/share/zsh/plugins/zsh-autopair/autopair.zsh | |
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh | |
export MCFLY_FUZZY="true" | |
export MCFLY_RESULTS="$LINES" | |
export MCFLY_INTERFACE_VIEW="BOTTOM" | |
export MCFLY_RESULTS_SORT="LAST_RUN" | |
eval "$(mcfly init zsh)" | |
# Enable FuZzyFind. | |
source /usr/share/fzf/completion.zsh | |
source /usr/share/fzf/key-bindings.zsh | |
# Enable CommandNotFound. | |
source /usr/share/doc/find-the-command/ftc.zsh | |
source /usr/share/doc/pkgfile/command-not-found.zsh | |
# Enable colored commands. | |
if [ -x $(which dircolors) ]; then | |
test -r ~/.dircolors \ | |
&& eval "$(dircolors -b ~/.dircolors)" \ | |
|| eval "$(dircolors -b)" | |
fi | |
export LESS_TERMCAP_mb=$'\E[1;31m' | |
export LESS_TERMCAP_md=$'\E[1;36m' | |
export LESS_TERMCAP_me=$'\E[0m' | |
export LESS_TERMCAP_so=$'\E[01;33m' | |
export LESS_TERMCAP_se=$'\E[0m' | |
export LESS_TERMCAP_us=$'\E[1;32m' | |
export LESS_TERMCAP_ue=$'\E[0m' | |
export LESSHISTFILE="$HOME/.local/state/lesshst" | |
export LESS="-F -J -M -R -S -X -a -e -i -j.5 -s \ | |
--file-size --incsearch --save-marks --mouse \ | |
--status-line --use-color --search-options=-EFW" | |
trap 'MANWIDTH="$[$COLUMNS-4]"' SIGWINCH | |
export MANWIDTH="$[$COLUMNS-4]" | |
export MANROFFOPT=" -c" | |
export MANPAGER="less" | |
alias jq='jq --color-output' | |
alias diff='diff --color -B -E -w' | |
alias grep='grep -P --color' | |
# Set key-bindings. | |
export WORDCHARS="" | |
bindkey -e | |
bindkey -r "^[c" | |
bindkey -r "^[s" | |
bindkey -r "^e" | |
bindkey -r "^s" | |
stty start "" | |
stty stop "" | |
stty susp "^b" | |
stty intr "^t" | |
stty lnext "^q" | |
stty eof "^x" | |
autoload -U -z select-word-style | |
zstyle select-word-style normal | |
bindkey " " magic-space | |
bindkey "^[c" clear-screen | |
bindkey "^?" backward-delete-char | |
bindkey "^[[3~" delete-char | |
bindkey "^[[4~" end-of-line | |
bindkey "^[[1~" beginning-of-line | |
bindkey "^[[Z" reverse-menu-complete | |
bindkey "^a" beginning-of-line | |
bindkey "^z" end-of-line | |
bindkey "^[m" run-help | |
bindkey "^[f" fzf-file-widget | |
bindkey "^[h" fzf-history-widget | |
bindkey "^h" up-history | |
bindkey "^[[104;6u" down-history | |
bindkey "^r" accept-line-and-down-history | |
bindkey "^g" vi-find-prev-char | |
bindkey "^[[103;6u" vi-find-next-char | |
bindkey "^[t" transpose-words | |
bindkey "^[T" transpose-chars | |
bindkey "^[^u" up-case-word | |
bindkey "^[^l" down-case-word | |
bindkey "^w" backward-word | |
bindkey "^[[119;6u" forward-word | |
bindkey "^[w" backward-kill-word | |
bindkey "^[W" kill-word | |
bindkey "^s" vi-backward-blank-word | |
bindkey "^[[115;6u" vi-forward-blank-word | |
autoload -U -z backward-kill-word-match | |
zle -N backward-kill-space-word backward-kill-word-match | |
zstyle :zle:backward-kill-space-word word-style space | |
bindkey "^[s" backward-kill-space-word | |
autoload -U -z kill-word-match | |
zle -N kill-space-word kill-word-match | |
zstyle :zle:kill-space-word word-style space | |
bindkey "^[S" kill-space-word | |
bindkey "^[a" backward-kill-line | |
bindkey "^[z" kill-line | |
bindkey "^[^s" yank | |
bindkey "^[^w" yank | |
bindkey "^[^y" yank | |
bindkey "^[\`" insert-last-word | |
autoload -U -z insert-composed-char | |
zle -N insert-composed-char | |
bindkey "^[^c" insert-composed-char | |
bindkey "^q" quoted-insert | |
autoload -U -z surround | |
zle -N add-surround surround | |
zle -N change-surround surround | |
zle -N delete-surround surround | |
bindkey "^[q^[a" add-surround | |
bindkey "^[q^[c" change-surround | |
bindkey "^[q^[d" delete-surround | |
_add-var-syntax-sugar() \ | |
{zle vi-backward-blank-word | |
RBUFFER="\"\${()${(U)RBUFFER}}\"" | |
zle vi-forward-blank-word} | |
zle -N add-var-syntax-sugar _add-var-syntax-sugar | |
bindkey "^[^v" add-var-syntax-sugar | |
autoload -U -z edit-command-line | |
zle -N edit-command-line | |
bindkey "^[e" edit-command-line | |
bindkey -s "^e^e" "echo " | |
bindkey -s "^e^s" "sudo " | |
bindkey -s "^e^f" "for in ; do ; done" | |
bindkey -s "^e^i" "if then ; else ; fi" | |
bindkey -s "^[^z" "^[." | |
bindkey -s "^[^a" "^[0^[." | |
# Set tab title. | |
tab-title() {echo -n "\e]0;$@\a"} | |
tab-title "($(lsb_release -s -i)_$(uname)@${$(uname -r)/-*})" | |
# Set command prompt. | |
[[ "$TERM" =~ "linux|.*color.*" ]] && set-prompt() { | |
XTCA=(1 3 2 4 7) | |
FGCG="%b%F{green}" | |
BATT_P="$(</sys/class/power_supply/BAT1/capacity)" | |
BATT_C=$XTCA[$[($BATT_P+19)/20]] | |
PS1_UH="$FGCG"$'\u250c'"(%B%F{blue}%n@%m$FGCG)" | |
PS1_VT="$FGCG"'[%B%F{cyan}%y'"$FGCG"']' | |
PS1_DIR="$FGCG{%B%F{white}%~$FGCG}" | |
PS1_BATT="$FGCG{%B%F{$BATT_C}$BATT_P%%$FGCG]" | |
PS1_TIME="$FGCG"'[%B%F{white}%D{%H:%M}'"$FGCG"']' | |
PS1_DATE="$FGCG(%B%F{blue}%D{%d/%m}$FGCG)" | |
PS1_NL="$SFGCG"$'\u2514'">%B%F{blue}$%b%F{white} " | |
PS1_UH_L="${#${(%)PS1_UH}//$'\x0f'#$'\e'\[[0-9]#m}" | |
PS1_VT_L="${#${(%)PS1_VT}//$'\x0f'#$'\e'\[[0-9]#m}" | |
PS1_DIR_L="${#${(%)PS1_DIR}//$'\x0f'#$'\e'\[[0-9]#m}" | |
PS1_BATT_L="${#${(%)PS1_BATT}//$'\x0f'#$'\e'\[[0-9]#m}" | |
PS1_TIME_L="${#${(%)PS1_TIME}//$'\x0f'#$'\e'\[[0-9]#m}" | |
PS1_DATE_L="${#${(%)PS1_DATE}//$'\x0f'#$'\e'\[[0-9]#m}" | |
PS1_PAD="${(r:$[COLUMNS-$PS1_UH_L-$PS1_VT_L-$PS1_DIR_L-$PS1_BATT_L-$PS1_TIME_L-$PS1_DATE_L-6]::─:)}" | |
PROMPT="$PS1_UH"$'\u2500'"$PS1_VT"$'\u2500'"$PS1_DIR"$'\u2500'"$PS1_PAD"$'\u2500'"$PS1_BATT"$'\u2500'"$PS1_TIME"$'\u2500'"$PS1_DATE"$'\n'"$PS1_NL" | |
} | |
precmd_functions+=(set-prompt) | |
# Set terminal blanking and locking. | |
local JUL=($(journalctl -n 2 -g "Unlocked")) | |
local LULTM="Last unlock: $JUL[14,16] on $JUL[22]" | |
alias cxxmatrix='cxxmatrix -s "number" -s "banner" -m $(fortune \ | |
| fold -s -w $[$MANWIDTH/8] | sed "s/ /_/g;s/--//")' | |
alias tty-clock='tty-clock -B -S -b -r -s -x -f "%Ai %d %B %Y"' | |
alias scrn-svr=' trap "" INT; cxxmatrix; tty-clock; trap - INT; tput reset' | |
alias term-lock='vlock; echo "\n$LULTM\n"; set-prompt; zle reset-prompt' | |
[[ "$TERM" =~ "tmux" ]] && {unset TMOUT} \ | |
|| {export TMOUT="300"; trap "scrn-svr; term-lock" SIGALRM | |
[[ "$TERM" =~ ".*color.*" ]] || setterm --blank 10} | |
# Define functions. | |
ghg-find() {FILTER="$1"; shift; gh gist list "$@" \ | |
--filter "$FILTER" | awk '/^[0-9a-z]/{print $1}'} | |
ghg-view() {gh gist view $(ghg-find "$@")} | |
ghg-flist() {gh gist view $(ghg-find "$@") --files} | |
ghg-fview() {gh gist view $(ghg-find "$1") -f "$2" --raw} | |
ghg-fedit() {gh gist edit $(ghg-find "$1") -f "$2" "$3"} | |
ghg-fadd() {gh gist edit $(ghg-find "$1") -a "$2" "$3"} | |
ghg-fremove() {gh gist edit $(ghg-find "$1") -r "$2" "$3"} | |
ghg-fpush() {ghg-fedit "$1" "${2##*/}@$HOST" "$2"} | |
ghg-clone() {gh gist clone $(ghg-find "$@")} | |
ghg-fvpull() {GIST=$( ghg-find "$1") | |
VERA=($(gh api /gists/$GIST/commits --jq ".[]|.version")) | |
VER=$VERA[${$(($3+1)):-1}] | |
URLA=($(gh api /gists/$GIST/$VER --jq ".files|..|.raw_url?")) | |
[[ $#URLA > 1 ]] && URLV=(${(M)URLA:#*$2*}) | |
[[ $#URLV > 1 ]] && URL=${(M)URLV:#*$HOST*} || URL="$URLA[1]" | |
echo $URL; unset -m GIST VER\* URL\*} | |
ghg-fvdiff() {diff <(curl -s $(ghg-fvpull "$1" "$2" "$3")) \ | |
<(curl -s $(ghg-fvpull "$1" "$2" "$4"))} | |
ghg-edit() {echo "GHGists:$1:$2"; ghg-fedit "$1" "${2##*/}" "$2" | |
ghg-fvdiff "$1" "${2##*/}" "1" "0"; echo} | |
ghg-push() {echo "GHGists:$1:$2"; ghg-fpush "$1" "$2" | |
ghg-fvdiff "$1" "${2##*/}%40$HOST" "1" "0"; echo} | |
ghg-rename() {{echo "GHGists:$1> "; ghg-flist "$1"; | |
gh gist rename $(ghg-find "$1") "$2" "$3" | |
echo " -> "; ghg-flist "$1"} | tr -d \\n; echo} | |
ghg-browse() {$BROWSER "${GH/www/gist}/$USER"/$(ghg-find $1)} | |
ghg-new() {gh gist create -d "$1" -p "$2"; ghg-view "$1"} | |
ghg-del() {gh gist delete $(ghg-find "$@")} | |
ghr-find() {M=${2:-1}; N=${3:-$M}; gh search repos ${=1} \ | |
-L ${5:-10} --json "fullName" --jq '.[].fullName' \ | |
| grep -m $M "${1%% *}" | sed -n ${3:-1},${4:-$N}p} | |
ghr-view() {gh repo view $(ghr-find $1 $2 $3)} | |
ghr-clone() {gh repo clone $(ghr-find $1 $2 $3)} | |
ghr-browse() {GH_BROWSER="lynx" gh browse -R \ | |
$(gh search repos --json "fullName" \ | |
--jq ".[].fullName" --limit 100 $@ \ | |
| fzf --sync --preview="gh repo view {1} | glow")} | |
ghr-fpull() {curl $(gh api repos/$(ghr-find $1 $3 $4)/contents/$2 \ | |
--jq '.download_url') > ${1// /_}:${2##*/}} | |
ghr-rel() { gh api repos/$(ghr-find $1 $2 $3)/releases \ | |
--jq '.[].assets[]|.browser_download_url'} | |
ghr-ffind() {GH_PAGER="$SHELL -c 'awk \"!/^$/&&NR>2\" \ | |
| fzf --ansi --sync --wrap --cycle \ | |
--preview-window=\"wrap,cycle\" \ | |
--preview=\"gh repo view {1} | glow\" \ | |
--bind=\"ctrl-r:execute(gh browse -n -R {1} | lynx -)\" \ | |
--bind=\"ctrl-f:execute(gh api repos/{1}/contents/{2} --jq .download_url | lynx -dump - | bat --file-name {2})\" \ | |
--bind=\"ctrl-d:execute(gh api repos/{1}/contents/{2} --jq .download_url | wget -q -i -)\"'" \ | |
gh search code --limit="100" --match="path" $@} | |
ghi-find() {gh search issues -L ${3:-10} --json="title,url" \ | |
--template='{{range .}}[{{.url}}] {{.title}}{{"\n"}}{{end}}' \ | |
--repo=$(ghr-find "$1") "$2" | cat -n} | |
ghi-view() {gh issue view --comments $(ghi-find "$1" "$2" "$4" \ | |
| awk -v FS='[\\[\\]]' "NR==${3:-1}"'{print $2}')} | |
ghi-browse() {$BROWSER $(ghi-find "$1" "$2" "$4" \ | |
| awk -v FS='[\\[\\]]' "NR==${3:-1}"'{print $2}')} | |
cant() {CMD="export RUN='sudo'"; FILE="$2:a" | |
while [[ $DIR != "/" ]]; do | |
TEST="[[ ! $1 $FILE ]]" | |
if eval "$TEST"; then | |
if [[ -e "$FILE" ]]; then | |
eval "$CMD"; break | |
else FILE="${FILE%/*/#}"; fi | |
else break; fi; done | |
unset CMD FILE TEST} | |
new() {DIR="${${${1:a}%/*/#}:-/}"; cant -w $DIR | |
[[ -d $DIR ]] || $RUN mkdir -p $DIR | |
[[ ${1##*/} ]] && {TYPE="file"; $RUN touch -m "$1"} \ | |
|| {TYPE="dir"; $RUN mkdir -p "$1"} | |
[[ $? == 0 ]] && echo "new $TYPE '$1:a'"; unset RUN} | |
edit() {cant -w $1; eval $RUN ${EDITOR:-vim} $@; unset RUN} | |
view() {cant -r $1; eval $RUN ${PAGER:-less} $@; unset RUN} | |
list() {cant -r ${1:-$PWD}; eval $RUN ls -ls $@; unset RUN} | |
copy() {cant -r $1; cant -w $2; eval $RUN cp -rv $@; unset RUN} | |
move() {cant -w $1; cant -w $2; eval $RUN mv -fv $@; unset RUN} | |
del() {cant -w $1; eval $RUN rm -rv $@; unset RUN} | |
vi-ex() {local EXEC=$(command -v $1) | |
[[ $(file -L "$EXEC") =~ "script" ]] \ | |
&& view "$EXEC" || file -L "$EXEC"} | |
ed-ex() {local EXEC=$(command -v $1) | |
[[ $(file -L "$EXEC") =~ "script" ]] \ | |
&& edit "$EXEC" || file -L "$EXEC"} | |
rn-ex() {local EXEC=$(command -v $1) | |
sudo mv -v "$EXEC" "${EXEC:h}/$2"} | |
mv-ex() {sudo mv -v "$1.sh" $(command -v "$1")} | |
cp-ex() {cp -v $(command -v "$1") "$1.sh"} | |
gstr-ex() {strings $(command -v "$1") | fold -w "$[$COLUMNS-2]" \ | |
| grep -C"${3:-1}" -- "$2" | LESS="$LESS +/$2" bat -l"less"} | |
asset() {fc -l -n -${1:-1} | sed 's/ARGV//g' >> ${2:-$SHRC} | |
edit -s <(<<<':sil$|:sil$,?^$?+1d') ${2:-$SHRC}} | |
dpl() {print -z "$1() {${${functions[$1]// ##/ }#$'\t'}}"} | |
def() {TYPE="${$(whence -w $1)#*: }"; CMD="$(typeset -h +m $TYPE\?\#s)[$1]"; \ | |
print ${${(P)CMD// ##/ }#$'\t'} | bat -l"$SH" --file-name \ | |
"$(whence -w "$1" | awk -v FS='[: ]' '{print $3": "$1}')"; unset -m TYPE CMD} | |
run-help-gh() {man "gh${1:+-$1}"} | |
help() {eval "$@" "--help |& $HELPPAGER"} | |
pvd() {PAGER="$HELPPAGER" glow -p "$DOC_DIR"/*$1*/*.{txt,md}} | |
men () {local LESS="$LESS --use-backslash +/${(q)${(q)1}}"; | |
if [[ -n $(man -w "$1") ]]; then | |
LESS="${(Q)${(Q)LESS}}" man "$1" | |
else if [[ -n $(man -K -w "$1") ]]; then | |
LESS="${(Q)${(Q)LESS}}" man -K "$1" | |
else man -K --regex "${(q)1}"; fi; fi} | |
name-info() { DIR="$1"; echo "f: $DIR" | |
{echo $(stat -c "%A %U %G" "$DIR") "${DIR##*/}" | |
while [[ "$DIR" != "/" ]]; do DIR="${${DIR%/*}:-/}" | |
echo $(stat -c "%A %U %G" "$DIR") "${${DIR##*/}:-/}"; done} | tr " " "\t" | tac} | |
rc-ct-wd() {rclone -L -P copyto --no-check-dest "$1" "${1##*/}"} | |
rc-cp-gd() {rclone -L -P copy {"$HOME","GDrive:"}/"${1}"} | |
rc-ct-gd() {rclone -L -P copyto {"$HOME","GDrive:"}/"${1}"} | |
rc-ct-gd_d() {local FILE="$LCONF_DIR/$1:t"; echo "GDrive:/$FILE" | |
diff -s <(rclone cat "GDrive:"/"$FILE") \ | |
<(cat "$HOME"/"$FILE"); rc-ct-gd "$FILE"; echo} | |
rs-bu() {eval rsync -v -a -P $1 $2 -f\ \'-\ \*\*${*:2}\*\*\'} | |
lc-bu() {copy "$HOME/"{,"$LCONF_DIR/"}"${1##*/}" | |
ghg-edit "$2" "$HOME/""$LCONF_DIR/""${1##*/}" | |
rc-ct-gd "$LCONF_DIR/""${1##*/}" | |
mount "/mnt/backup/" | |
copy {"$HOME/","/mnt/backup/"}"$LCONF_DIR/""${1##*/}" | |
umount "/mnt/backup/"} | |
pf() {paru -S -s $* | grep -A1 /$1-} | |
pfn() {PKGS=$(paru -S -s $* | unexpand -t4) | |
[[ "$ZSH_SUBSHELL" = "0" ]] \ | |
&& OPT_ARG="-i -B1 \t.*$1" \ | |
|| OPT_ARG="-o ^[\w/.-]+$1[\w.-]+" | |
grep -P "$=OPT_ARG" <<< "$=PKGS" | expand -t4} | |
pfw() {paru -S -i $1 | awk "/^URL/"'{print $3}'} | |
pFf() {pfn "$1" | fzf --preview="paru -S -i {}"} | |
pfF() {[[ "$ZSH_SUBSHELL" = "0" ]] || OPTS="-q" | |
paru -F -x $OPTS "$1"} | |
pei() {paru -F -x $1; PKG_VER=$(paru -F -x /$1.1 \ | |
| awk '{print $(NF-1)"@"$NF}' | uniq) | |
echo "\nDo you want to install $PKG_VER?\n" | |
paru -S "${PKG_VER%@*}"; unset PKG_VER} | |
peI() {paru -Q -o -q $(whence -p $1)} | |
psd() {echo $PARU_DIR/$1*/src/$1*/} | |
pmi() {makepkg -e -i -D $HOME/.cache/paru/clone/$1} | |
pbE() {cd $HOME/.cache/paru/clone; paru -G $1 | |
edit $1/PKGBUILD; paru -B $1; cd -} | |
pip-dir() {echo $(pip show $1 | awk -v FS='[: ]' /Loc/'{print $3}')/${1//-/_}} | |
pipx-dir() {echo "$PIPX_HOME/venvs/$1/lib/${${(L)$(python -V)/ }%.*}/site-packages/$1"} | |
chperm() {awk -v RS='[()]' 'NR==1{opts=$0}; NR%2==0{print "chmod "opts" "$0}' <<< "$@" | $SH} | |
mpv-yth() {VID=$(yt-dlp -v --get-id --playlist-items ${1:-1} \ | |
--cookies-from-browser chrome+gnomekeyring :ythistory) | |
mpv -v --ytdl-format=135+140 ytdl://$VID} | |
spiral() {AWL=$(xprop -root | awk "/${(q)NAWW}/"'{print $5}') | |
xseticon -id "${AWL/,}" "$1"} | |
xfce4() {eval "xfce4-$1" & {sleep 1; spiral "$ICON_DIR/org.xfce.$1.png"};} | |
nsurf() {OPTS=$(fbset | awk /geom/'{print "-b "$6" -w "$4" -h "$5}') | |
eval netsurf-fb -f sdl $OPTS $@} | |
wps() {$BROWSER $(surfraw -p wikipedia "$@" | sed 's_/wiki/_/w/_')} | |
sos() {so --no-lucky -l 100 "$1" -s "${2:-$SOF}" -e "${3:-$G}"} | |
uses() {sos "$1" unix stackexchange} | |
google() {eval surfraw -browser=$BROWSER google $1} | |
status() { systemctl status $1.service} | |
start() {sudo systemctl start $1.service; status $1} | |
stop() {sudo systemctl stop $1.service; status $1} | |
ports() {awk -v FS='[/ ]+' /$1/'{print $2; exit}' /etc/services} | |
wfg() {grep -i "$1" "$WORDSFILE"} | |
bkg() {bindkey | grep -i ${${1//\^/\\^}//\[/\\[} \ | |
| sort -k 2 | tr " " "\t" | expand -t 10} | |
alg() {print -l -C 2 ${(k)aliases[(R)*$1*]}= \ | |
${(v)aliases[(R)*$1*]}} | |
fung() {print -l -C 2 ${(k)functions[(R)*$1*]}= \ | |
${(v)functions[(R)*$1*]}} | |
varset() {local VAR="${(U)${*% =*}// /_}" | |
eval $VAR="${(q)*#*= }" | |
echo $VAR=\"${(P)VAR}\"} | |
alfred() {TYPE="${$(whence -w $1)#*: }" | |
if [[ "$TYPE" == "none" ]] | |
then VAR="$1"; else \ | |
VAR=\"$(typeset -h +m $TYPE\?\#s)\[$1\]\"; fi | |
eval vared -c -h $VAR; unset TYPE VAR} | |
fret() {typeset -f -t "$1" | |
{eval "${(q)@}"} |& bat -l"$SH" --file-name="function: $1" | |
typeset -f +t "$1"} | |
fate() {chmod +x =(hb; def "$1"; echo "$1 \$@") & wait | |
FATE=$(echo "$TMPPREFIX"[[:IDENT:]](#c6)(xcs-1));} | |
fax() {fate "$1"; shift; parallel "$FATE" ::: "$@" | |
rm "$FATE"; unset FATE} | |
very() {vim -s <( <<< YZZ) <( <<< $1)} | |
epoch() {date -d "@ $1"} | |
# Define aliases. | |
alias pi='paru -S' | |
alias pI='paru -S -i' | |
alias pu='paru -S -y -u' | |
alias pD='paru -S -d -d -w' | |
alias pc='paru -c -c -o' | |
alias pl='paru -Q -l' | |
alias po='paru -Q -o' | |
alias pd='paru -R' | |
alias varpr='typeset -m' | |
alias unset='unset -m' | |
alias she='edit "$HF"' | |
alias esc='edit "$SHRC"' | |
alias sl='ln -s -v' | |
alias mir='chmod -v +x' | |
alias hb='echo "#!/usr/bin/env $SH\n"' | |
alias sed='sed -r -s -u' | |
alias dd=' dd status=progress' | |
alias pip-find='pypi-simple-search' | |
alias verve='ed -s <<< /^\"\"0/+1,/^\"1/-2p ~/.viminfo' | |
alias abt="ascii -b | unexpand -t4 \ | |
| rs -c$'\t' -C$'\t' -T \ | |
| rs -c$'\t' -C$'\t' 1 0 \ | |
| rs -c$'\t' -C$' ' -T \ | |
| rs -c$'\n' -C$'\t' -t 0 16 \ | |
| expand -t4 | sed -r 's/^ +| +$//g'" | |
alias rc-ls=' rclone -L lsf' | |
alias rc-cat='rclone -L cat' | |
alias rc-ct=' rclone -L copyto -P' | |
alias rc-ct-gd-sch='local FILES=($HF $SHRC); \ | |
eval rc-ct-gd_d\ ${^FILES}\;' | |
alias ghg-push-sch='local FILES=(${(U)SH}\\\ {$H\ $HF,conf\ $SHRC}); \ | |
eval ghg-push\ \ ${^FILES}\;' | |
alias borsch='lc-bu "$SHRC"; lc-bu "$HF"; rc-ct-gd-sch; ghg-push-sch' | |
alias spin='rclone sync -P {GDrive:,$HOME}/Pictures/; mount /mnt/backup | |
rsync -P -i -r -a -h -@1 {$HOME,/mnt/backup}/Pictures/; umount /mnt/backup' | |
alias ghg-list='gh gist list --include-content --filter' | |
alias gh-cps='gh copilot suggest' | |
alias gg='gemini --multiline --model="gemini-2.5-flash" \ | |
--style="dracula" --term "\!" --wrap="$COLUMNS"' | |
alias top='btop -t' | |
alias mem=' free -h -l -t -v --si' | |
alias pst=' pstree -a -c -C age -g -h -l -n -p -s -S -t -u -U -Z $USER' | |
alias sudo='sudo -A -B -E -H -p "[sudo] Enter password for user $USER: "' | |
alias rb='sudo systemctl reboot ' | |
alias sb='sudo systemctl suspend' | |
alias train='sl -a -c -d -e -F -G -10 -l -w' | |
alias cmatrix='cmatrix -C green -L -a -b -f -u 10' | |
alias csf='cowsay -e "@@" -r -C -W "$MANWIDTH" $(fortune) -n' | |
alias meteo='wttr -n $(curl -s ipinfo.io/$(myip public) | jq -r .city)' | |
alias open='mimeopen' | |
alias pager='less -N' | |
alias nv='nvim' | |
alias nvp='nvimpager' | |
alias mplay='mpv' | |
alias minfo='mediainfo' | |
alias files='clifm' | |
alias trash='trash-put -f -v' | |
alias web='lynx' | |
alias browser='links -g' | |
alias w3m='w3m -F -H -N -W -X -r -s -v \ | |
-cookie -debug -graph -title' | |
alias vsh='bat -l$SH' | |
alias vmd=' PAGER="$HELPPAGER" glow -p -w "$MANWIDTH"' | |
alias aws='wikiman -H $BROWSER -a -c -k' | |
alias tldr='PAGER="$HELPPAGER" tldr --pager' | |
alias reddit=' tuir --enable-media' | |
alias wp='wiki-tui --language english' | |
alias ftmb='fb-tmux-bg' | |
alias wsh='ttyd -W -p"2222" "$SH" & \ | |
www "localhost:2222"; pkill -1 "ttyd"' | |
alias reader='fbgs -r 200 -d /dev/dri/card1' | |
alias show=' fbi -a -d /dev/dri/card1' | |
alias tl-it-en=' trans it:en' | |
alias tl-en-it=' trans en:it' | |
alias etym='etymology-cli -a' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment