#!/bin/sh # The MIT License (MIT) # # Copyright (c) 2026 pacman64 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # aliases # # # This is a collection of arguably useful shell aliases/shortcuts which # should work on any modern shell, except when tools aren't installed. # # Some of these commands depend on my other scripts from the `pac-tools`, # others either rely on widely-preinstalled command-line apps, or ones # which are available on most of the major command-line `package` managers. # # To use this script, you're supposed to `source` it, so its definitions # stay for your whole shell session: for that, you can run `source aliases` # or `. aliases` (no quotes either way), either directly or at shell login. case "$1" in -h|--h|-help|--help) # show help message, using the info-comment from this very script awk ' /^case / { exit } /^# +aliases$/, /^$/ { gsub(/^# ?/, ""); print } ' "$0" exit 0 ;; esac # dash doesn't support regex-matching syntax, forcing to use case statements case "$0" in -bash|-dash|-sh|bash|dash|sh|/bin/sh) # script is being sourced with bash, dash, or ash, which is good : ;; *) case "$ZSH_EVAL_CONTEXT" in *:file) # script is being sourced with zsh, which is good : ;; *) # script is being run normally, which is a waste of time printf "\e[7mDon't run this script directly: instead source it\e[0m\n" printf "\e[7mby running '. aliases' (without the single quotes).\e[0m\n" # exiting during shell-startup may deny shell access, even if # the script is being run, instead of being sourced directly ;; esac ;; esac alias 0='sbs' alias 1='bsbs 1' alias 2='bsbs 2' alias 3='bsbs 3' alias 4='bsbs 4' alias 5='bsbs 5' alias 6='bsbs 6' alias 7='bsbs 7' alias 8='bsbs 8' alias 9='bsbs 9' # Less with Header n runs `less` with line numbers, ANSI styles, without # line-wraps, and using the first n lines as a sticky-header, so they always # show on top alias lh1='less --header=1 -MKNiCRS' alias lh2='less --header=2 -MKNiCRS' alias lh3='less --header=3 -MKNiCRS' alias lh4='less --header=4 -MKNiCRS' alias lh5='less --header=5 -MKNiCRS' alias lh6='less --header=6 -MKNiCRS' alias lh7='less --header=7 -MKNiCRS' alias lh8='less --header=8 -MKNiCRS' alias lh9='less --header=9 -MKNiCRS' # View with Header n runs `less` without line numbers, ANSI styles, without # line-wraps, and using the first n lines as a sticky-header, so they always # show on top alias vh1='less --header=1 -MKiCRS' alias vh2='less --header=2 -MKiCRS' alias vh3='less --header=3 -MKiCRS' alias vh4='less --header=4 -MKiCRS' alias vh5='less --header=5 -MKiCRS' alias vh6='less --header=6 -MKiCRS' alias vh7='less --header=7 -MKiCRS' alias vh8='less --header=8 -MKiCRS' alias vh9='less --header=9 -MKiCRS' alias c='cat' alias e='echo' alias r='reset' # load/concatenate BYTES from named data sources alias bytes='cat' # Compile C Optimized alias cco='cc -Wall -O2 -s -march=native -mtune=native -flto' # Color DMESG alias cdmesg='dmesg --color=always' # Colored Json Query runs the `jq` app, allowing an optional filepath as the # data source, and even an optional transformation formula alias cjq='jq -C' # CLear Screen alias cls='reset' # Compile C Plus Plus Optimized alias cppo='c++ -Wall -O2 -s -march=native -mtune=native -flto' # Colored RipGrep ensures app `rg` emits colors when piped alias crg='rg --color=always' # Compile Rust Optimized alias cro='rustc -C lto=true -C codegen-units=1 -C debuginfo=0 -C strip=symbols -C opt-level=3' # CURL Silent spares you the progress bar, but still tells you about errors alias curls='curl --silent --show-error' # turn JSON Lines into a proper json array alias dejsonl='jq -s -M' # turn json lines into a proper json array using the `jq` app alias dejql='jq -s -M' # turn UTF-16 data into UTF-8 alias deutf16='iconv -f utf16 -t utf8' # ENV with 0/null-terminated lines on stdout alias env0='env -0' # ENV Change folder, runs the command given in the folder given (first) alias envc='env -C' # Extended Plain Interactive Grep alias epig='ugrep --color=never -Q -E' # Editor Read-Only alias ero='micro -readonly true' # run the Fuzzy Finder (fzf) in multi-choice mode, with custom keybindings alias ff='fzf -m --bind ctrl-a:select-all,ctrl-space:toggle' # get FILE's MIME types alias filemime='file --mime-type' # run `gcc` with all optimizations on and with static analysis on alias gccmax='gcc -Wall -O2 -s -march=native -mtune=native -flto -fanalyzer' # GO Build Stripped alias gobs='go build -ldflags "-s -w" -trimpath' # hold stdout if used at the end of a pipe-chain alias hold='less -MKiCRS' # shrink/compact JSON using the `jq` app, allowing an optional filepath, and # even an optional transformation formula after that alias jq0='jq -c -M' # show JSON data on multiple lines, using 2 spaces for each indentation level, # allowing an optional filepath, and even an optional transformation formula # after that alias jq2='jq --indent 2 -M' # find the LAN (local-area network) IP address for this device alias lanip='hostname -I' # run `less`, showing line numbers, among other settings alias least='less -MKNiCRS' # ensure LINES are never accidentally joined across files, by always emitting # a line-feed at the end of each line alias lines='awk 1' # try to run the command given using line-buffering for its (standard) output alias livelines='stdbuf -oL' # LiSt files, showing how many 4K-sized storage blocks they use alias ls4k='ls -s --block-size=4096' # LOAD data from the filename given alias load='cat' # Live RipGrep alias lrg='rg --line-buffered' # run `ls` showing how many 4k pages each file takes alias lspages='ls -s --block-size=4096' # run `less`, showing line numbers, among other settings alias most='less -MKNiCRS' # Number all lines counting from 0, using a tab right after each line number alias n0='nl -b a -w 1 -v 0' # Number all lines counting from 1, using a tab right after each line number alias n1='nl -b a -w 1 -v 1' # Nice Json Query colors JSON data using the `jq` app alias njq='jq -C' # show the current date and time alias now="date +'%Y-%m-%d %H:%M:%S'" # Plain Interactive Grep alias pig='ugrep --color=never -Q -E' # Plain RipGrep alias prg='rg --color=never' # Quick Compile C Optimized alias qcco='cc -Wall -O2 -s -march=native -mtune=native -flto' # Quick Compile C Plus Plus Optimized alias qcppo='c++ -Wall -O2 -s -march=native -mtune=native -flto' # Quiet MPV alias qmpv='mpv --really-quiet' # Read-Only Editor alias roe='micro -readonly true' # Read-Only Micro (text editor) alias rom='micro -readonly true' # Read-Only Top alias rot='htop --readonly' # RUN IN folder alias runin='env -C' # SystemCTL; `sysctl` is already taken for a separate/unrelated app alias sctl='systemctl' # Silent CURL spares you the progress bar, but still tells you about errors alias scurl='curl --silent --show-error' # Stdbuf Output Line-buffered alias sol='stdbuf -oL' # TINY GO Build Optimized alias tinygobo='tinygo build -no-debug -opt=2' # Timed Make, also showing max memory used alias tm="/usr/bin/time -f 'real %e user %U sys %S mem %M' make" # show current date in a specifc format alias today="date +'%Y-%m-%d %a %b %d'" # Time Verbosely the command given alias tv='/usr/bin/time -v' # go UP 1 folder alias up='cd ..' # run `cppcheck` with even stricter options alias vetc='cppcheck --enable=portability,style --check-level=exhaustive' # run `cppcheck` with even stricter options, also checking for c89 compliance alias vetc89='cppcheck --enable=portability,style --check-level=exhaustive --std=c89' # run `cppcheck` with even stricter options alias vetcpp='cppcheck --enable=portability,style --check-level=exhaustive' # VET SHell scripts alias vetsh='shellcheck -e 3043' # check shell scripts for common gotchas, avoiding complaints about using # the `local` keyword, which is widely supported in practice alias vetshell='shellcheck -e 3043' # run a command using an empty environment alias void='env -i' # turn plain-text from latin-1 into UTF-8; the name is from `vulgarization`, # which is the mutation of languages away from latin during the middle ages alias vulgarize='iconv -f latin-1 -t utf-8' # run `xargs`, using zero/null bytes as the extra-arguments terminator alias x0='xargs -0' # show the current date in the YYYY-MM-DD format alias ymd="date +'%Y-%m-%d'"