dotfiles/bash/.bash_aliases

209 lines
5.6 KiB
Bash
Executable File

# git
alias gitp="git push"
alias gitpl="git pull"
alias gitplu="git pull upstream"
alias gitom="git push origin master"
alias gitf="git fetch"
alias gits="git status"
alias gitch="git checkout $1"
alias gitd="git diff"
alias gitb="git branch"
alias gitr="git remote"
alias gitfc="gitf && gitch"
alias gita="git add"
alias gitap="git add -p"
alias gitrp="git checkout -p"
function gitc {
if [ -z "$1" ]; then
git commit
else
git commit -m "$@"
fi
}
function gitcp {
gitc "$@" && gitp;
}
alias gitlg="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset by %an' --abbrev-commit --date=relative"
function mcd {
mkdir $1 && cd $1;
}
function calc {
echo "$@" | bc
}
alias cls="clear"
alias vimdiff="nvim -d"
alias cp='cp -iv' # Preferred 'cp' implementation
alias mv='mv -iv' # Preferred 'mv' implementation
alias mkdir='mkdir -p' # Preferred 'mkdir' implementation
alias ll='ls -FGlAhp' # Preferred 'ls' implementation
alias less='less -FSRXc' # Preferred 'less' implementation
lcd() { builtin cd "$@"; ll; } # Always list directory contents upon 'cd'
alias cd..='cd ../' # Go back 1 directory level (for fast typers)
alias ..='cd ../' # Go back 1 directory level
alias ...='cd ../../' # Go back 2 directory levels
alias ....='cd ../../../' # Go back 3 directory levels
alias ~="cd ~" # ~: Go Home
alias c='clear' # c: Clear terminal display
alias path='echo -e ${PATH//:/\\n}' # path: Echo all executable Paths
mcd () { mkdir -p "$1" && cd "$1"; } # mcd: Makes new Dir and jumps inside
# copilot
ghcs() {
TARGET="shell"
local GH_DEBUG="$GH_DEBUG"
local GH_HOST="$GH_HOST"
read -r -d '' __USAGE <<-EOF
Wrapper around \`gh copilot suggest\` to suggest a command based on a natural language description of the desired output effort.
Supports executing suggested commands if applicable.
USAGE
$FUNCNAME [flags] <prompt>
FLAGS
-d, --debug Enable debugging
-h, --help Display help usage
--hostname The GitHub host to use for authentication
-t, --target target Target for suggestion; must be shell, gh, git
default: "$TARGET"
EXAMPLES
- Guided experience
$ $FUNCNAME
- Git use cases
$ $FUNCNAME -t git "Undo the most recent local commits"
$ $FUNCNAME -t git "Clean up local branches"
$ $FUNCNAME -t git "Setup LFS for images"
- Working with the GitHub CLI in the terminal
$ $FUNCNAME -t gh "Create pull request"
$ $FUNCNAME -t gh "List pull requests waiting for my review"
$ $FUNCNAME -t gh "Summarize work I have done in issues and pull requests for promotion"
- General use cases
$ $FUNCNAME "Kill processes holding onto deleted files"
$ $FUNCNAME "Test whether there are SSL/TLS issues with github.com"
$ $FUNCNAME "Convert SVG to PNG and resize"
$ $FUNCNAME "Convert MOV to animated PNG"
EOF
local OPT OPTARG OPTIND
while getopts "dht:-:" OPT; do
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
OPT="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "$OPT" in
debug | d)
GH_DEBUG=api
;;
help | h)
echo "$__USAGE"
return 0
;;
hostname)
GH_HOST="$OPTARG"
;;
target | t)
TARGET="$OPTARG"
;;
esac
done
# shift so that $@, $1, etc. refer to the non-option arguments
shift "$((OPTIND-1))"
TMPFILE="$(mktemp -t gh-copilotXXXXXX)"
trap 'rm -f "$TMPFILE"' EXIT
if GH_DEBUG="$GH_DEBUG" GH_HOST="$GH_HOST" gh copilot suggest -t "$TARGET" "$@" --shell-out "$TMPFILE"; then
if [ -s "$TMPFILE" ]; then
FIXED_CMD="$(cat $TMPFILE)"
history -s $(history 1 | cut -d' ' -f4-); history -s "$FIXED_CMD"
echo
eval "$FIXED_CMD"
fi
else
return 1
fi
}
ghce() {
local GH_DEBUG="$GH_DEBUG"
local GH_HOST="$GH_HOST"
read -r -d '' __USAGE <<-EOF
Wrapper around \`gh copilot explain\` to explain a given input command in natural language.
USAGE
$FUNCNAME [flags] <command>
FLAGS
-d, --debug Enable debugging
-h, --help Display help usage
--hostname The GitHub host to use for authentication
EXAMPLES
# View disk usage, sorted by size
$ $FUNCNAME 'du -sh | sort -h'
# View git repository history as text graphical representation
$ $FUNCNAME 'git log --oneline --graph --decorate --all'
# Remove binary objects larger than 50 megabytes from git history
$ $FUNCNAME 'bfg --strip-blobs-bigger-than 50M'
EOF
local OPT OPTARG OPTIND
while getopts "dh-:" OPT; do
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
OPT="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "$OPT" in
debug | d)
GH_DEBUG=api
;;
help | h)
echo "$__USAGE"
return 0
;;
hostname)
GH_HOST="$OPTARG"
;;
esac
done
# shift so that $@, $1, etc. refer to the non-option arguments
shift "$((OPTIND-1))"
GH_DEBUG="$GH_DEBUG" GH_HOST="$GH_HOST" gh copilot explain "$@"
}
dlog() {
docker start $1
docker logs -f $1
}
ww() {
cmd.exe /C "$@"
}