flake-update-20260505
 1# Auto-expanding aliases — expands abbreviations on space
 2typeset -ga _vbe_abbrevations
 3abbrev-alias() {
 4  alias $1
 5  _vbe_abbrevations+=(${1%%\=*})
 6}
 7_vbe_zle-autoexpand() {
 8  local -a words; words=(${(z)LBUFFER})
 9  if (( ${#_vbe_abbrevations[(r)${words[-1]}]} )); then
10    zle _expand_alias
11  fi
12  zle magic-space
13}
14zle -N _vbe_zle-autoexpand
15bindkey -M emacs " " _vbe_zle-autoexpand
16bindkey -M emacs "^ " magic-space
17bindkey -M isearch " " magic-space
18
19# Correct common typos
20has git  && abbrev-alias gti=git
21has grep && abbrev-alias grpe=grep
22has sudo && abbrev-alias suod=sudo
23has ssh  && abbrev-alias shs=ssh
24
25# Save keystrokes
26has git && abbrev-alias gls="git ls-files"
27has ip && { abbrev-alias ip6='ip -6'; abbrev-alias ipb='ip -brief'; }
28abbrev-alias tailf="tail -F"
29has mpv && abbrev-alias mpva="mpv --no-video"
30
31# Systemd aliases (inlined, no anonymous function)
32if [[ -d /run/systemd/system ]]; then
33  local _sc="${(%):-%(#..sudo )}systemctl"
34  abbrev-alias start="$_sc start"
35  abbrev-alias stop="$_sc stop"
36  abbrev-alias reload="$_sc reload"
37  abbrev-alias restart="$_sc restart"
38  abbrev-alias status="$_sc status"
39  abbrev-alias ustart="systemctl --user start"
40  abbrev-alias ustop="systemctl --user stop"
41  abbrev-alias ureload="systemctl --user reload"
42  abbrev-alias urestart="systemctl --user restart"
43  abbrev-alias ustatus="systemctl --user status"
44  unset _sc
45fi
46
47# Grep aliases (inlined, no anonymous function or fork)
48alias grep="command grep --color=auto"
49abbrev-alias rgrep="grep -r"
50abbrev-alias egrep="grep -E"
51abbrev-alias fgrep="grep -F"
52(( $+commands[zgrep] )) && alias zgrep="GREP=grep command zgrep --color=auto"
53
54# nixpkgs runner
55(( $+commands[nix] )) && nixpkgs() {
56  cmd=$1; shift
57  nix run nixpkgs\#${cmd} -- "$@"
58}
59
60# File viewer
61v() {
62  case $(file --brief --mime-type $1 2>/dev/null) in
63    image/svg+xml) ;;
64    image/*) (( $+commands[nsxiv] )) && ${I3SOCK+i3-tabbed} nsxiv $1; return ;;
65    video/*) (( $+commands[mpv] )) && ${I3SOCK+i3-tabbed} mpv --no-fs $1; return ;;
66  esac
67  if (( $+commands[bat] )); then
68    if (( ! $# )); then
69      gzip -cdfq | bat
70    else
71      for f in "$@"; do gzip -cdfq -- $f | bat --file-name ${f%.gz}; done
72    fi
73  elif (( $+commands[less] )); then
74    gzip -cdfq -- "$@" | less -FX
75  elif (( $+commands[more] )); then
76    gzip -cdfq -- "$@" | more
77  else
78    gzip -cdfq -- "$@"
79  fi
80}
81
82# jayrah
83[[ -d ${HOME}/src/github.com/chmouel/jayrah ]] && \
84  alias jayrah="uv --directory=${HOME}/src/github.com/chmouel/jayrah run jayrah"