├── .gitignore ├── LICENSE ├── README.md ├── functions ├── mkcd └── mkpw └── init.zsh /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.zwc 3 | *.zwc.old 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2015-2016 Matt Hamilton and contributors 4 | Copyright (c) 2016-2024 Eric Nielsen, Matt Hamilton and contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | utility 2 | ======= 3 | 4 | Utility aliases and functions. 5 | 6 | Adds colour to `ls`, `grep` and `less`. To disable colours, add the following to 7 | your `~/.zshrc` before initialing this module: 8 | 9 | export NO_COLOR=1 10 | 11 | If file `${HOME}/.dir_colors` exists, then its configuration will be set using 12 | `dircolors` (GNU only). 13 | 14 | If [`lsd`] (LSDeluxe) is available, it will be aliased to `ls`. 15 | 16 | Aliases 17 | ------- 18 | 19 | ### ls 20 | 21 | * `ls` lists directories first (GNU only) and with colour (applies to all aliases below). 22 | * `ll` lists with long format and human-readable sizes (applies to all aliases below). 23 | * `l` lists all files. 24 | * `lm` lists all files using pager. 25 | * `lr` lists recursively (as a tree with `lsd`). 26 | * `lx` lists sorted by extension (GNU or `lsd` only). 27 | * `lk` lists sorted by largest file size last. 28 | * `lt` lists sorted by newest modification time last. 29 | * `lc` lists sorted by newest status change (ctime) last (not with `lsd`). 30 | 31 | ### File downloads 32 | 33 | * `get` downloads from the given URL using `aria2c`, `axel`, `wget` or `curl`. 34 | 35 | ### Resource usage 36 | 37 | * `df` reports file system disk usage with human-readable sizes. 38 | * `du` reports file disk usage with human-readable sizes. 39 | 40 | ### Condoms 41 | 42 | * `chmod` changes file mode verbosely, not operating from `/` (GNU only). 43 | * `chown` changes file owner verbosely, not operating from `/` (GNU only). 44 | * `rm` uses `safe-rm` if available. 45 | 46 | Functions 47 | --------- 48 | 49 | * `mkcd` creates and changes to the given directory. 50 | * `mkpw` generates a random password with the given length and set of characters. 51 | The default parameters are equivalent to `mkpw 32 0-9A-Za-z`. 52 | 53 | [`lsd`]: https://github.com/lsd-rs/lsd 54 | -------------------------------------------------------------------------------- /functions/mkcd: -------------------------------------------------------------------------------- 1 | # vim:et sts=2 sw=2 ft=zsh 2 | [[ -n ${1} ]] && mkdir -p ${1} && builtin cd ${1} 3 | -------------------------------------------------------------------------------- /functions/mkpw: -------------------------------------------------------------------------------- 1 | # vim:et sts=2 sw=2 ft=zsh 2 | LC_CTYPE=C command tr -dc ${2:-'[:alnum:]'} < /dev/urandom | command head -c ${1:-32} && print 3 | -------------------------------------------------------------------------------- /init.zsh: -------------------------------------------------------------------------------- 1 | # 2 | # Utility aliases and settings 3 | # 4 | 5 | # Set less or more as the default pager. 6 | if (( ! ${+PAGER} )); then 7 | if (( ${+commands[less]} )); then 8 | export PAGER=less 9 | else 10 | export PAGER=more 11 | fi 12 | fi 13 | 14 | if (( ! ${+LESS} )); then 15 | export LESS='--ignore-case --jump-target=4 --LONG-PROMPT --no-init --quit-if-one-screen --RAW-CONTROL-CHARS' 16 | fi 17 | 18 | # 19 | # File Downloads 20 | # 21 | 22 | # order of preference: aria2c, axel, wget, curl. This order is derrived from speed based on personal tests. 23 | if (( ${+commands[aria2c]} )); then 24 | alias get='aria2c --max-connection-per-server=5 --continue' 25 | elif (( ${+commands[axel]} )); then 26 | alias get='axel --num-connections=5 --alternate' 27 | elif (( ${+commands[wget]} )); then 28 | alias get='wget --continue --progress=bar --timestamping' 29 | elif (( ${+commands[curl]} )); then 30 | alias get='curl --continue-at - --location --progress-bar --remote-name --remote-time' 31 | fi 32 | 33 | 34 | # 35 | # Resource Usage 36 | # 37 | 38 | alias df='df -h' 39 | alias du='du -h' 40 | 41 | 42 | # 43 | # Colours 44 | # 45 | 46 | # See https://no-color.org 47 | if [[ -z ${NO_COLOR} ]]; then 48 | 49 | # grep colours 50 | if (( ! ${+GREP_COLOR} )) export GREP_COLOR='37;45' #BSD 51 | if (( ! ${+GREP_COLORS} )) export GREP_COLORS="mt=${GREP_COLOR}" #GNU 52 | if [[ ${OSTYPE} == (openbsd|solaris)* ]]; then 53 | if (( ${+commands[ggrep]} )) alias grep='ggrep --color=auto' 54 | elif (( ${+commands[grep]} )); then 55 | alias grep='grep --color=auto' 56 | fi 57 | 58 | # less colours 59 | if (( ! ${+LESS_TERMCAP_mb} )) export LESS_TERMCAP_mb=$'\E[1;31m' # Begins blinking. 60 | if (( ! ${+LESS_TERMCAP_md} )) export LESS_TERMCAP_md=$'\E[1;31m' # Begins bold. 61 | if (( ! ${+LESS_TERMCAP_me} )) export LESS_TERMCAP_me=$'\E[0m' # Ends mode. 62 | if (( ! ${+LESS_TERMCAP_ue} )) export LESS_TERMCAP_ue=$'\E[0m' # Ends underline. 63 | if (( ! ${+LESS_TERMCAP_us} )) export LESS_TERMCAP_us=$'\E[1;32m' # Begins underline. 64 | fi 65 | 66 | 67 | # 68 | # ls GNU vs. BSD 69 | # 70 | 71 | if whence dircolors >/dev/null && ls --version &>/dev/null; then 72 | # GNU 73 | 74 | # ls aliases 75 | alias lx='ll -X' # long format, sort by extension 76 | if [[ -z ${NO_COLOR} ]]; then 77 | # ls colours 78 | if [[ -s ${HOME}/.dir_colors ]]; then 79 | eval "$(dircolors --sh ${HOME}/.dir_colors)" 80 | elif (( ! ${+LS_COLORS} )); then 81 | export LS_COLORS='di=1;34:ln=35:so=32:pi=33:ex=31:bd=1;36:cd=1;33:su=30;41:sg=30;46:tw=30;42:ow=30;43' 82 | fi 83 | alias ls='ls --group-directories-first --color=auto' 84 | else 85 | alias ls='ls --group-directories-first' 86 | fi 87 | 88 | # Always wear a condom 89 | alias chmod='chmod --preserve-root -v' 90 | alias chown='chown --preserve-root -v' 91 | else 92 | # BSD 93 | 94 | if [[ -z ${NO_COLOR} ]]; then 95 | # ls colours 96 | export CLICOLOR=1 97 | if (( ! ${+LSCOLORS} )) export LSCOLORS=ExfxcxdxbxGxDxabagacad 98 | # Stock OpenBSD ls does not support colors at all, but colorls does. 99 | if [[ ${OSTYPE} == openbsd* && ${+commands[colorls]} -ne 0 ]]; then 100 | alias ls=colorls 101 | fi 102 | fi 103 | fi 104 | 105 | 106 | # 107 | # ls Aliases 108 | # 109 | 110 | alias ll='ls -lh' # long format and human-readable sizes 111 | alias l='ll -A' # long format, all files 112 | alias lm="l | ${PAGER}" # long format, all files, use pager 113 | alias lk='ll -Sr' # long format, largest file size last 114 | alias lt='ll -tr' # long format, newest modification time last 115 | if (( ${+commands[lsd]} )); then 116 | alias ls=lsd 117 | alias lr='ll --tree' # long format, recursive as a tree 118 | alias lx='ll -X' # long format, sort by extension 119 | else 120 | alias lr='ll -R' # long format, recursive 121 | alias lc='lt -c' # long format, newest status change (ctime) last, not supported by lsd 122 | fi 123 | 124 | 125 | # not aliasing rm -i, but if safe-rm is available, use condom. 126 | # if safe-rmdir is available, the OS is suse which has its own terrible 'safe-rm' which is not what we want 127 | if (( ${+commands[safe-rm]} && ! ${+commands[safe-rmdir]} )); then 128 | alias rm=safe-rm 129 | fi 130 | --------------------------------------------------------------------------------