Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created December 30, 2023 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/91bf239d37da1732bde1256de825b0c2 to your computer and use it in GitHub Desktop.
Save ormaaj/91bf239d37da1732bde1256de825b0c2 to your computer and use it in GitHub Desktop.
aliases
\unset -v aliasrestore
aliasrestore=$(\alias -p) aliasrestore+=${aliasrestore:+$'\n\\'unset -v aliasrestore}
\unalias -a
function setupGlobalAliases {
\alias \-- \
'--=-- ' \
'l-=local -' \
'fn=function ' \
'ts=typeset' \
'exec=exec ' \
'nameref=typeset -n' \
"integer=typeset -${KSH_VERSION+l}i" \
'command=command ' \
'nohup=nohup '
# eval alias "$(compgen -A keyword -A builtin | sed -Ee $'s|.*|@&=\'& \' @@&=&|;$q;s|$| \\\\|')"
}
function lindaMeHarder {
typeset -- x IFS=' '
typeset -A interactiveAliases
typeset -a lsopts=(--color=always --time-style '+%F %T' --group-directories-first --dereference-command-line-symlink-to-dir --quoting-style=shell-escape-always -h)
typeset -a ezaopt=(--color=always --time-style '+%F %T' --group-directories-first --hyperlink --git-ignore -@HMlhgi)
typeset -a treeopt=(-augphDC --metafirst)
typeset -a lsdefs=(
ls ls "" "${lsopts[*]@Q}"
lsl ls -l "${lsopts[*]@Q}"
lal ls -al "${lsopts[*]@Q}"
lol eza "" "${ezaopt[*]@Q}"
lzl eza -a "${ezaopt[*]@Q}"
tree tree "" "${treeopt[*]@Q}"
)
set -- "${!lsdefs[@]}"
set -- "${@:1:$#/4}"
for x; do
(( x *= 4 ))
set -- "${lsdefs[@]:x:2}" ${lsdefs[x+2]:+"${lsdefs[x+2]}"} "${lsdefs[x+3]}"
interactiveAliases+=([$1]=${*:2})
done
unset -v IFS
for x in emaint emerge; do
printf -v 'interactiveAliases[$x]' '%q ' ionice -c 3 -- nice -n +5 -- schedtool -De
interactiveAliases+=([$x]+=$x)
done
if x=$(type -P nvim); then
printf -v 'interactiveAliases[vim]' %q "$x"
fi
interactiveAliases+=(
[bashfds]='lsfd -Q "fd >= 0" -o +flags -p "$BASHPID"'
[sdo]='\sudo -EC 1024'
[cp]='cp --reflink=auto --sparse=always'
[whois]='whois -H'
[eapi]='okular --unique -- "$(equery -q f -f doc app-doc/pms:live | \grep --color=never -E "pms.pdf\$")" >/dev/null 2>&1 &'
[pdev]='PATH=$(readlink -qne ~ormaaj/doc/programs/portage/bin):${PATH##+(:)} PYTHONPATH=$(readlink -qne ~ormaaj/doc/programs/portage/lib):${PYTHONPATH##+(:)} '
[gdb]='gdb -q'
[grep]='grep --color=auto'
[info]='info --vi-keys'
[pst]='(exec -- ps -wHN --ppid 2 -p "2,$BASHPID" -o user,sid,pid,pgid,tpgid,tty,command)'
[dmesg]='dmesg -L=always'
[findmnt]='findmnt -o+propagation'
[ltup]='losetup -Pv --direct-io=on --find --show'
[ltupl]='losetup -lav --output-all'
[pedit]='nvim /etc/portage/{@(make.conf?(*(.+(?)).include)|bashrc?([[:digit:]])|repos.conf),package.{use/use,accept_keywords/keywords,unmask/unmask,mask/mask}}'
[ipup]='sysctl --system; ip addr add "${2}/24" dev "$1"; ip link set "$1" up; ip route add default via 192.168.0.1; ip -c -s -r -h addr show dev "$1"'
)
typeset -A fd
shopt -s expand_aliases
for x in "${!interactiveAliases[@]}"; do
alias -- "${x}=${interactiveAliases[$x]}"
done
# for x in "${!interactiveAliases[@]}"; do
# alias -- \
# "${x}_a=${interactiveAliases[$x]%%+([[:space:]])} " \
# "${x}_b=command -- " \
# "${x}_c=\"\$@\"" \
# "${x}_d=${x}_a ${x}_b"
# { source "/proc/self/fd/${fd[0]}"; exec {fd[0]}<&-; } {fd[0]}<<-EOF0
# function ${x} {
# ${interactiveAliases[$x]}
# }
# EOF0
#
# typeset -fp "$x"
# done
}
${aliasrestore+'eval'} ${BASH_VERSION+${aliasrestore+'--'}} ${aliasrestore+"$aliasrestore"}
# vim: set ft=bash fenc=utf-8 ff=unix ts=4 noet :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment