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