File: aliases.sh
   1 #!/bin/sh
   2 
   3 # The MIT License (MIT)
   4 #
   5 # Copyright (c) 2026 pacman64
   6 #
   7 # Permission is hereby granted, free of charge, to any person obtaining a copy
   8 # of this software and associated documentation files (the "Software"), to deal
   9 # in the Software without restriction, including without limitation the rights
  10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11 # copies of the Software, and to permit persons to whom the Software is
  12 # furnished to do so, subject to the following conditions:
  13 #
  14 # The above copyright notice and this permission notice shall be included in
  15 # all copies or substantial portions of the Software.
  16 #
  17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23 # SOFTWARE.
  24 
  25 
  26 # aliases
  27 #
  28 #
  29 # This is a collection of arguably useful shell aliases/shortcuts which
  30 # should work on any modern shell, except when tools aren't installed.
  31 #
  32 # Some of these commands depend on my other scripts from the `pac-tools`,
  33 # others either rely on widely-preinstalled command-line apps, or ones
  34 # which are available on most of the major command-line `package` managers.
  35 #
  36 # To use this script, you're supposed to `source` it, so its definitions
  37 # stay for your whole shell session: for that, you can run `source aliases`
  38 # or `. aliases` (no quotes either way), either directly or at shell login.
  39 
  40 
  41 case "$1" in
  42     -h|--h|-help|--help)
  43         # show help message, using the info-comment from this very script
  44         awk '
  45             /^case / { exit }
  46             /^# +aliases$/, /^$/ { gsub(/^# ?/, ""); print }
  47         ' "$0"
  48         exit 0
  49     ;;
  50 esac
  51 
  52 
  53 # dash doesn't support regex-matching syntax, forcing to use case statements
  54 case "$0" in
  55     -bash|-dash|-sh|bash|dash|sh|/bin/sh)
  56         # script is being sourced with bash, dash, or ash, which is good
  57         :
  58     ;;
  59 
  60     *)
  61         case "$ZSH_EVAL_CONTEXT" in
  62             *:file)
  63                 # script is being sourced with zsh, which is good
  64                 :
  65             ;;
  66 
  67             *)
  68                 # script is being run normally, which is a waste of time
  69         printf "\e[7mDon't run this script directly: instead source it\e[0m\n"
  70         printf "\e[7mby running '. aliases' (without the single quotes).\e[0m\n"
  71                 # exiting during shell-startup may deny shell access, even if
  72                 # the script is being run, instead of being sourced directly
  73             ;;
  74         esac
  75     ;;
  76 esac
  77 
  78 
  79 alias 0='sbs'
  80 
  81 alias 1='bsbs 1'
  82 alias 2='bsbs 2'
  83 alias 3='bsbs 3'
  84 alias 4='bsbs 4'
  85 alias 5='bsbs 5'
  86 alias 6='bsbs 6'
  87 alias 7='bsbs 7'
  88 alias 8='bsbs 8'
  89 alias 9='bsbs 9'
  90 
  91 # Less with Header n runs `less` with line numbers, ANSI styles, without
  92 # line-wraps, and using the first n lines as a sticky-header, so they always
  93 # show on top
  94 alias lh1='less --header=1 -MKNiCRS'
  95 alias lh2='less --header=2 -MKNiCRS'
  96 alias lh3='less --header=3 -MKNiCRS'
  97 alias lh4='less --header=4 -MKNiCRS'
  98 alias lh5='less --header=5 -MKNiCRS'
  99 alias lh6='less --header=6 -MKNiCRS'
 100 alias lh7='less --header=7 -MKNiCRS'
 101 alias lh8='less --header=8 -MKNiCRS'
 102 alias lh9='less --header=9 -MKNiCRS'
 103 
 104 # View with Header n runs `less` without line numbers, ANSI styles, without
 105 # line-wraps, and using the first n lines as a sticky-header, so they always
 106 # show on top
 107 alias vh1='less --header=1 -MKiCRS'
 108 alias vh2='less --header=2 -MKiCRS'
 109 alias vh3='less --header=3 -MKiCRS'
 110 alias vh4='less --header=4 -MKiCRS'
 111 alias vh5='less --header=5 -MKiCRS'
 112 alias vh6='less --header=6 -MKiCRS'
 113 alias vh7='less --header=7 -MKiCRS'
 114 alias vh8='less --header=8 -MKiCRS'
 115 alias vh9='less --header=9 -MKiCRS'
 116 
 117 alias c='cat'
 118 alias e='echo'
 119 alias r='reset'
 120 
 121 # load/concatenate BYTES from named data sources
 122 alias bytes='cat'
 123 
 124 # Compile C Optimized
 125 alias cco='cc -Wall -O2 -s -march=native -mtune=native -flto'
 126 
 127 # Color DMESG
 128 alias cdmesg='dmesg --color=always'
 129 
 130 # Colored Json Query runs the `jq` app, allowing an optional filepath as the
 131 # data source, and even an optional transformation formula
 132 alias cjq='jq -C'
 133 
 134 # CLear Screen
 135 alias cls='reset'
 136 
 137 # Compile C Plus Plus Optimized
 138 alias cppo='c++ -Wall -O2 -s -march=native -mtune=native -flto'
 139 
 140 # Colored RipGrep ensures app `rg` emits colors when piped
 141 alias crg='rg --color=always'
 142 
 143 # Compile Rust Optimized
 144 alias cro='rustc -C lto=true -C codegen-units=1 -C debuginfo=0 -C strip=symbols -C opt-level=3'
 145 
 146 # CURL Silent spares you the progress bar, but still tells you about errors
 147 alias curls='curl --silent --show-error'
 148 
 149 # turn JSON Lines into a proper json array
 150 alias dejsonl='jq -s -M'
 151 
 152 # turn json lines into a proper json array using the `jq` app
 153 alias dejql='jq -s -M'
 154 
 155 # turn UTF-16 data into UTF-8
 156 alias deutf16='iconv -f utf16 -t utf8'
 157 
 158 # ENV with 0/null-terminated lines on stdout
 159 alias env0='env -0'
 160 
 161 # ENV Change folder, runs the command given in the folder given (first)
 162 alias envc='env -C'
 163 
 164 # Extended Plain Interactive Grep
 165 alias epig='ugrep --color=never -Q -E'
 166 
 167 # Editor Read-Only
 168 alias ero='micro -readonly true'
 169 
 170 # run the Fuzzy Finder (fzf) in multi-choice mode, with custom keybindings
 171 alias ff='fzf -m --bind ctrl-a:select-all,ctrl-space:toggle'
 172 
 173 # get FILE's MIME types
 174 alias filemime='file --mime-type'
 175 
 176 # run `gcc` with all optimizations on and with static analysis on
 177 alias gccmax='gcc -Wall -O2 -s -march=native -mtune=native -flto -fanalyzer'
 178 
 179 # GO Build Stripped
 180 alias gobs='go build -ldflags "-s -w" -trimpath'
 181 
 182 # hold stdout if used at the end of a pipe-chain
 183 alias hold='less -MKiCRS'
 184 
 185 # shrink/compact JSON using the `jq` app, allowing an optional filepath, and
 186 # even an optional transformation formula after that
 187 alias jq0='jq -c -M'
 188 
 189 # show JSON data on multiple lines, using 2 spaces for each indentation level,
 190 # allowing an optional filepath, and even an optional transformation formula
 191 # after that
 192 alias jq2='jq --indent 2 -M'
 193 
 194 # find the LAN (local-area network) IP address for this device
 195 alias lanip='hostname -I'
 196 
 197 # run `less`, showing line numbers, among other settings
 198 alias least='less -MKNiCRS'
 199 
 200 # ensure LINES are never accidentally joined across files, by always emitting
 201 # a line-feed at the end of each line
 202 alias lines='awk 1'
 203 
 204 # try to run the command given using line-buffering for its (standard) output
 205 alias livelines='stdbuf -oL'
 206 
 207 # LiSt files, showing how many 4K-sized storage blocks they use
 208 alias ls4k='ls -s --block-size=4096'
 209 
 210 # LOAD data from the filename given
 211 alias load='cat'
 212 
 213 # Live RipGrep
 214 alias lrg='rg --line-buffered'
 215 
 216 # run `ls` showing how many 4k pages each file takes
 217 alias lspages='ls -s --block-size=4096'
 218 
 219 # run `less`, showing line numbers, among other settings
 220 alias most='less -MKNiCRS'
 221 
 222 # Number all lines counting from 0, using a tab right after each line number
 223 alias n0='nl -b a -w 1 -v 0'
 224 
 225 # Number all lines counting from 1, using a tab right after each line number
 226 alias n1='nl -b a -w 1 -v 1'
 227 
 228 # Nice Json Query colors JSON data using the `jq` app
 229 alias njq='jq -C'
 230 
 231 # show the current date and time
 232 alias now="date +'%Y-%m-%d %H:%M:%S'"
 233 
 234 # Plain Interactive Grep
 235 alias pig='ugrep --color=never -Q -E'
 236 
 237 # Plain RipGrep
 238 alias prg='rg --color=never'
 239 
 240 # Quick Compile C Optimized
 241 alias qcco='cc -Wall -O2 -s -march=native -mtune=native -flto'
 242 
 243 # Quick Compile C Plus Plus Optimized
 244 alias qcppo='c++ -Wall -O2 -s -march=native -mtune=native -flto'
 245 
 246 # Quiet MPV
 247 alias qmpv='mpv --really-quiet'
 248 
 249 # Read-Only Editor
 250 alias roe='micro -readonly true'
 251 
 252 # Read-Only Micro (text editor)
 253 alias rom='micro -readonly true'
 254 
 255 # Read-Only Top
 256 alias rot='htop --readonly'
 257 
 258 # RUN IN folder
 259 alias runin='env -C'
 260 
 261 # SystemCTL; `sysctl` is already taken for a separate/unrelated app
 262 alias sctl='systemctl'
 263 
 264 # Silent CURL spares you the progress bar, but still tells you about errors
 265 alias scurl='curl --silent --show-error'
 266 
 267 # Stdbuf Output Line-buffered
 268 alias sol='stdbuf -oL'
 269 
 270 # TINY GO Build Optimized
 271 alias tinygobo='tinygo build -no-debug -opt=2'
 272 
 273 # Timed Make, also showing max memory used
 274 alias tm="/usr/bin/time -f 'real %e    user %U    sys %S    mem %M' make"
 275 
 276 # show current date in a specifc format
 277 alias today="date +'%Y-%m-%d %a %b %d'"
 278 
 279 # Time Verbosely the command given
 280 alias tv='/usr/bin/time -v'
 281 
 282 # go UP 1 folder
 283 alias up='cd ..'
 284 
 285 # run `cppcheck` with even stricter options
 286 alias vetc='cppcheck --enable=portability,style --check-level=exhaustive'
 287 
 288 # run `cppcheck` with even stricter options, also checking for c89 compliance
 289 alias vetc89='cppcheck --enable=portability,style --check-level=exhaustive --std=c89'
 290 
 291 # run `cppcheck` with even stricter options
 292 alias vetcpp='cppcheck --enable=portability,style --check-level=exhaustive'
 293 
 294 # VET SHell scripts
 295 alias vetsh='shellcheck -e 3043'
 296 
 297 # check shell scripts for common gotchas, avoiding complaints about using
 298 # the `local` keyword, which is widely supported in practice
 299 alias vetshell='shellcheck -e 3043'
 300 
 301 # run a command using an empty environment
 302 alias void='env -i'
 303 
 304 # turn plain-text from latin-1 into UTF-8; the name is from `vulgarization`,
 305 # which is the mutation of languages away from latin during the middle ages
 306 alias vulgarize='iconv -f latin-1 -t utf-8'
 307 
 308 # run `xargs`, using zero/null bytes as the extra-arguments terminator
 309 alias x0='xargs -0'
 310 
 311 # show the current date in the YYYY-MM-DD format
 312 alias ymd="date +'%Y-%m-%d'"