1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 16:09:03 -08:00
rc/home/shrc
Connor Olding a2ae5a212d rename ~/.-shrc to ~/.shrc
the reason for the hyphen is that i was originally concerned
about random shells executing the file when i didn't want them to.
back then, i was only targetting zsh and bash, and therefore
`~/.-shrc` was not yet suitable for any other shells.
nowadays, `~/.-shrc` is has better shell compatibility,
and i'm not actually aware of any shells that would execute
`~/.shrc` by default -- `$ENV` is typically required to be set.
2021-10-29 15:44:31 +02:00

170 lines
8.2 KiB
Text

#!/usr/bin/env false
# for ash, dash, bash, and zsh.
[ -n "$ZSH_VERSION" -o -n "$BASH_VERSION" ] && FANCY=1 || FANCY=0
if [ "$FANCY" = 0 ]; then
. ~/.prep # handle boring stuff like /etc/profile and $PATH
fi
# {{{1 utilities
have() {
if [ -z "$ZSH_VERSION" ]; then which -- "$1"; else whence -p -- "$1"; fi
} 2>/dev/null
has() {
have "$@"
} >/dev/null
if has sudo; then
maybesudo() { sudo "$@"; }
else
maybesudo() { maybesudo_ "$@"; }
fi
ADDPATH() { ### @- append a directory to `$PATH` if it isn't already present.
if [ "$1" != "${1#[A-Z]:\\}" ]; then
set -- "$(cygpath -u "$1")"
fi
local new="$(readlink -f "$1")"
if [ ! -d "$new" ]; then
printf 'ADDPATH: path does not exist: %s\n' "$1" >&2
return 1
fi
case ":$PATH:" in
(*":$new:"*) :;;
(*) export PATH="$PATH:$new";;
esac
}
# {{{1 configurations
umask 022 # umask should be reset else pip might make faulty installations.
ADDPATH "$HOME/opt/local/bin"
# cleanup in case of inherited exports:
unset PREFIX CC CPP CXX LD CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
unset AR RANLIB RC WINDRES OBJDUMP OBJCOPY
unset LD_LIBRARY_PATH
[ "$DESKTOP_SESSION" != xfce ] || export QT_QPA_PLATFORMTHEME="" # unhide menu bar
#[ "$TERM" != vt102 ] || export TERM="xterm" # PuTTY over serial
export EA_AUTH="auth"
export EA_DIR="t"
export EA_DOMAIN="https://eaguru.guru"
export EDITOR=vim
export ENV="$HOME/.shrc" # for dash and ash
export PAGER=less
export PYTHONIOENCODING=utf-8 # damnit python!
export SSH_AUTH_SOCK=0 # more info: https://0x0.st/NUnw
export TZ=':/etc/localtime' # more info: https://0x0.st/NUnv
# $LANG has been my bane whenever i forget to set it properly, so check it.
if [ "$LANG" != "en_US.UTF-8" ] && [ "$LANG" != "en_CA.UTF-8" ]; then
if [ -z "$MSYSTEM" ] || [ "$LANG" != "C.UTF-8" ]; then
printf 'Warning: LANG is %s\n' "${LANG:-empty!}" >&2
fi
fi
# aliases {{{1
# enable colors {{{2
if [ "$FANCY" = 1 ]; then
# busybox is smart enough to ignore --color flags when unsupported.
alias grep='grep --color=auto'
alias ls='ls --color=auto'
alias lr="lr -G"
#alias make="$(have colormake || have make)"
fi
# just flags {{{2
export LESS='-SRQc'
alias db="dropbox_uploader"
alias fils="du -bahd1" ### @- (GNU du) display human-friendly filesizes for the files in a directory.
alias lsa="ls -A --group-directories-first" ### @- (GNU ls) list files with directories and dotfiles ordered first.
alias perlu='perl -Mopen=locale -Mutf8' ### @- invoke perl expecting files with UTF-8 encoding.
alias rgn="rg --no-ignore" ### @- invoke ripgrep without respecting `.gitignore` files.
alias cms="cryptominisat5 --verb 0" ### @- invoke cryptominisat5 with less noise.
alias curls="curl -sS" ### @- invoke curl with less noise.
alias curLs="curl -L --no-progress-meter"
# git {{{2
alias get="git clone --single-branch --depth 1" ### @- retrieve the most recent files from the default branch of a git repository, and not much else.
alias gs='git status' ### @- invoke git's status subcommand.
### **TODO:** consider renaming because gs(1) already exists.
alias gd='git diff -U2' ### @- invoke git's diff subcommand with fewer lines of context.
alias gds='git --no-pager diff --stat' ### @- display difference stats from git.
alias gl='git log --oneline' ### @- invoke git's log subcommand with a single line per commit.
### **TODO:** consider renaming because [gl(1)](https://github.com/gitless-vcs/gitless) already exists.
alias glo='git log --graph --decorate --pretty=oneline --abbrev-commit --all' ### @- navigate git's commit tree succinctly.
alias g1='git log --pretty=oneline --abbrev-commit --color=always | head -1' ### @- display the most recent git commit.
alias g11='git rev-parse --short HEAD'
alias gr='git remote -v' ### @- display remote git repositories verbosely.
alias gb='git --no-pager branch' ### @- display the current git branch.
### **NOTE:** there also exists a gb(1) program provided by
### the *gb* package that i don't use.
gdp() { ### @- invoke `gd` to diff a commit from its parent. the commit defaults to "HEAD".
local commit="${1:-HEAD}"
[ $# -le 1 ] || { printf '%s: %s\n' gdp "too many arguments" >&2; return 2; }
gd "$commit~" "$commit"
}
# being specific {{{2
alias ash="PS1='$ ' busybox ash"
alias cort='LC_ALL=C sort'
alias pip="maybesudo -H pip3"
alias revend='objcopy -I binary -O binary --reverse-bytes=4' ### @- reverse the 4-byte endianness of a single file. *this is an in-place operation!*
alias clone='maybesudo rsync -aHA --info=progress2 --no-i-r' ### @- invoke rsync suitably for creating virtually indistinguishable copies of files.
alias aligntabs="column -t -s$'\t'" ### @- align tab-delimited fields in stdin.
alias crawla='ssh joshua@crawl.akrasiac.org -i ~/.ssh/crawl' ### @- play Dungeon Crawl: Stone Soup through ssh on the akrasiac server.
alias crawlz='ssh crawl@crawl.develz.org -i ~/.ssh/crawl' ### @- play Dungeon Crawl: Stone Soup through ssh on the develz server.
alias eahead='ea head' ### @- deprecated name for [`ea head`.](#ea)
alias eaget='ea get' ### @- deprecated name for [`ea get`.](#ea)
alias eaput='ea put' ### @- deprecated name for [`ea put`.](#ea)
alias eamove='ea move' ### @- deprecated name for [`ea move`.](#ea)
alias eacopy='ea copy' ### @- deprecated name for [`ea copy`.](#ea)
alias eadelete='ea delete' ### @- deprecated name for [`ea delete`.](#ea)
alias eamv='ea move' ### @- invoke [`ea move`.](#ea)
alias eacp='ea copy' ### @- invoke [`ea copy`.](#ea)
alias earm='ea delete' ### @- invoke [`ea delete`.](#ea)
### @ ll - list files verbosely, fancily, ordered, but not recursively.
if has lr; then
alias ll='ify less lr -1lshGG -o tev'
else
alias ll='ify less ls -lAX --group-directories-first --color=force'
fi
# providing extra functionality {{{2
alias diff="git diff --color=auto --no-ext-diff --no-index --no-prefix" ### @- use git's diff subcommand for general diffing.
alias gc="git column --mode=dense --padding=2" ### @- columnize text by using git's column subcommand.
### **TODO:** consider renaming because gc(1) already exists.
alias counts='find . | wc -l' ### @- count files in the current directory, including files found recursively.
alias exts="find -type f | grep -o '\\.[^/.]*$' | sort | uniq -c | sort -n" ### @- count and sort file extensions in the current directory, including files found recursively.
alias nocom='grep -Ev --line-buffered --color=never "^[[:space:]]*(//|#)"' ### @- strip single-line C-like and shell-like comments.
alias jrep='grep -aPo "[\x{20}-\x{7E}\x{4E00}-\x{9FFF}\x{3040}-\x{30FF}]+"' ### @- extract strings comprised of basic ASCII or Japanese codepoints.
alias bomb='uconv -f utf-8 -t utf-8 --add-signature' ### @- add a Byte-Order Mark to a file.
alias cleanse='tr -cd "\11\12\15\40-\176"' ### @- strip unprintable and non-ASCII characters.
alias unwrap='awk '\''BEGIN{RS="\n\n";FS="\n"}{for(i=1;i<=NF;i++)printf "%s ",$i;print "\n"}'\' ### @- join paragraphs into one line each.
alias double='awk "{print;print}"' ### @- print every line twice. <br/> print every line twice.
### **NOTE:** there also exists a double(1) program provided by
### the *plotutils* package that i don't use.
alias join2='paste -d" " - -' ### @- join every other line.
alias katagana='perlu -MUnicode::Normalize -pe'"'"'$_=NFKD($_)=~y/ァ-ヶ /ぁ-ゖ /r'"'" ### @- convert katakana codepoints to their equivalent hiragana.
### this is occasionally useful when translating [debug text from ancient games.](https://tcrf.net/)
alias picky='comm -23 <(pacman -Qetq | sort -u) <(pacman -Qgq base base-devel xorg xorg-drivers xfce4 mingw-w64-x86_64-toolchain 2>/dev/null | sort -u) | tr -d "\t"' ### @-
### list pacman packages that were manually installed and are not in some common package groups.
### this list can be used to assist later reinstalls.
alias unused='comm -23 <(pacman -Qtq) <(pacman -Qeq) | tr -d "\t"' ### @-
### list pacman packages that weren't installed explicitly and don't satisfy any dependencies.
### this list can be used to free up some disk space.
alias makepkgf='makepkg -Af --skipchecksums --skippgpcheck' ### @- make the freakin' package!
alias rakef='rake && gem build *.gemspec && gem install *.gem' ### @- make the freakin' gem!
pl() { printf '%s\n' "$@"; } ### @- print each argument on its own line.