Last active
August 30, 2024 17:33
-
-
Save m-thomson/680080f984af10fb0e2a3af80ac60094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
######################################################## | |
## .bash_reuse | |
######################################################## | |
## This file contains aliases and functions that can be | |
## re-used across systems (Mac and Linux). These must be | |
## sourced from the .bashrc or .bash_profile but can also | |
## be used in a Keyboard Maestro macro (or similar) to | |
## "type" them into a terminal window | |
######################################################## | |
echo "💫 Sourcing .bash_reuse (Remember: use 'alias' to show shell aliases and 'funcs' to show functions)" >&2 | |
echo "🐚 Bash v${BASH_VERSION} on ${OSTYPE}" >&2 | |
######################################################## | |
# Shell settings | |
######################################################## | |
# -- Append to history, don't overwrite it | |
shopt -s histappend | |
# -- Bash autocomplete ignoring case https://superuser.com/a/435127/396106 | |
bind "set completion-ignore-case on" | |
export EDITOR='nano' | |
# These are bash only. | |
# - Don't put duplicate lines or lines starting with space in the history. | |
# - Append to the history file, don't overwrite it | |
# - For setting history length see HISTSIZE and HISTFILESIZE in bash(1) | |
# - Check the window size after each command and update the values of LINES and COLUMNS. | |
HISTCONTROL=ignoreboth | |
HISTSIZE=1000 | |
HISTFILESIZE=2000 | |
shopt -s histappend | |
shopt -s checkwinsize | |
######################################################## | |
# Shell aliases | |
######################################################## | |
# -- Note: on MacOS, ls is also aliased to use gnu ls | |
alias l='ls -CXAGFh --group-directories-first --color=auto' | |
alias ll='ls -XAGFhl --group-directories-first --color=auto' | |
alias la='ls -A' | |
# Options explained: | |
# -C list entries by columns | |
# -X sort alphabetically by entry extension | |
# -A, --almost-all do not list implied . and .. | |
# -G, --no-group in a long listing, don't print group names | |
# -l use a long listing format | |
# -h, --human-readable with -l and/or -s, print human readable sizes | |
# -F, --classify append indicator (one of */=>@|) to entries | |
# -- Redo the last command with sudo. Two versions depending on mood :) | |
alias fuck='sudo $(fc -nl -1)' | |
alias please='sudo $(fc -nl -1)' | |
# -- Misc | |
alias ..="cd .." | |
alias h="history" | |
alias g="grep -E -i" | |
alias m="more" | |
alias hig='history|grep -E -i' | |
alias tre="tree -C -F --dirsfirst --filelimit 20" | |
alias treed="tree --si -C -s --du -F|grep -F '/'" | |
alias zscat="zstd -cd" | |
alias path='echo $PATH|tr ":" "\n"|sort --ignore-case' | |
alias usage="echo 'List size of immediate subfolders'>&2; du -h --max-depth=1" | |
alias hosts="sudo nano /etc/hosts; echo 'Remember to flush DNS cache if needed (alias: flush-dns) '" | |
alias funcs="declare -f|grep -E '^[a-zA-Z0-9][-a-zA-Z0-9_]* \(\)'|grep -v '^nvm_'" | |
alias bat="bat --theme=Dracula" | |
# -- Docker | |
alias drps="docker ps --format \"table {{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Ports}}\"|sed -r 's/:::([^,])+(, |$)//g'" | |
# -- Github Copilot CLI | |
alias howto="gh copilot suggest -t shell" | |
alias explain="gh copilot explain" | |
# -- Use less as a replacement for head and tail commands. +G = go to end -S = Prevent text wrap -n = Prevent line numbers | |
alias head2='less -S -n' | |
alias tail2='less -S +G -n' | |
# -- Allow quick editing (and reload) of bash configs | |
alias edit-profile="nano ~/.bash_profile && echo Use \\'reload-profile\\' to update current session to latest edits" | |
alias reload-profile="source ~/.bash_profile" | |
alias edit-rc="nano ~/.bashrc && echo Use \\'reload-rc\\' to update current session to latest edits" | |
alias reload-rc="source ~/.bashrc" | |
# -- tmux | |
alias ta='tmux attach' | |
# -- just | |
alias jmenu="just --choose" | |
alias j="just --unstable" | |
# -- SSH | |
alias sendpvtkey="ssh-copy-id -i ~/.ssh/id_rsa.pub " | |
# -- Fairnames | |
alias fn='cd "$FN_CODE_DIR"' | |
# -- Clear DNS cache on linux (macOS has it's own version) | |
alias flush-dns="sudo systemd-resolve --flush-caches && echo 'Cache cleared. This assumes you are using systemd-resolved DNS services';" | |
######################################################## | |
# Shell functions | |
######################################################## | |
######################################################## | |
# End of .bash_reuse | |
######################################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment