-
Notifications
You must be signed in to change notification settings - Fork 1
/
dot_aliases.sh
191 lines (166 loc) · 5.41 KB
/
dot_aliases.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
# Misc aliases
# Git
## Fix oh-my-zsh git plugin
#unalias gg
#unalias gga
alias ungit="find . -name '.git' -exec rm -rf {} \;"
alias gb='git branch'
alias gba='git branch -a'
alias gc='git commit -v'
alias gca='git commit -v -a'
# Commit pending changes and quote all args as message
function gg() {
git commit -v -a -m "$*"
}
alias gco='git checkout '
alias gd='git diff'
alias gdm='git diff master'
alias gl='git pull'
alias gnp="git-notpushed"
alias gp='git push'
alias gst='git status'
alias gt='git status'
alias g='git status'
alias eg='subl .git/config'
alias gbd='git branch -D'
# Git clone from GitHub
function gch() {
git clone git://github.com/$USER/$1.git
}
function gitgrep() {
git rev-list --all | xargs git grep $@
}
alias git_clean_merged_branches='git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d'
# Setup a tracking branch from [remote] [branch_name]
function gbt() {
git branch --track $2 $1/$2 && git checkout $2
}
# Quickly clobber a file and checkout
function grf() {
rm $1
git checkout $1
}
# Run mutt under plain xterm TERM type
alias mutt='TERM=xterm mutt'
# Run irssi in screen type term so scrooling works in tmux
alias irssi='TERM=screen-256color irssi'
alias beep='echo -en "\007"'
if [ "${DISTRIBUTION}" = "Darwin" ]; then
alias topc='top -o cpu'
alias flushdns='dscacheutil -flushcache'
# Quick way to rebuild the Launch Services database and get rid
# # of duplicates in the Open With submenu.
alias fixopenwith='/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user'
# alias ls='exa --git'
function notify() {
osascript -e "display notification \"$*\" with title \"Shell notification\""
}
# iTerm name tab function
function nametab() { echo -ne "\033]0;"$@"\007"; }
# Homebrew
alias brewski='brew update && brew upgrade --greedy && brew cleanup; brew doctor'
# TailScale
alias tailscale=/Applications/Tailscale.app/Contents/MacOS/Tailscale
alias vpn-dev="open https://fido-challenger.githubapp.com/auth/vpn-devvpn && osascript -e 'tell application \"Viscosity\" to connect \"github-iad-devvpn\"'"
alias vpn-prod="open https://fido-challenger.githubapp.com/auth/vpn-prod && osascript -e 'tell application \"Viscosity\" to connect \"github-iad-prod\"'"
alias secpass_save='function _secpass_save(){ security add-generic-password -a hilli -s $1 -w $2 };_secpass_save'
alias secpass_lookup='function _secpass_lookup(){ security find-generic-password -a hilli -s $1 -w };_secpass_lookup'
fi
if [ "${DISTRIBUTION}" = "debian" ]; then
alias open="gnome-open"
fi
if [ "$(uname)" = "Linux" ]; then
# Add some color when using GNU ls
alias d="ls --color"
alias ls="ls --color=auto"
alias ll="ls --color -l"
fi
alias rssh="ssh -t -o RemoteCommand='sudo su -'"
alias pssh="ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no"
function dkwhois() {
whois -h whois.dk-hostmaster.dk " --show-handles --charset=utf-8 $1"
}
# Docker
# http://kartar.net/2014/03/some-useful-docker-bash-functions-and-aliases/
# Remove all stopped containvers
alias drm="docker rm \$(docker ps -q -a)"
# Remove all non-used images
alias dri="docker rmi \$(docker images -q)"
# Run image in interactive container
alias dki="docker run -t -i -P"
function dcontext() {
echo "Setting docker context to"
if [ -z "$1" ]; then
docker context use default
else
docker context use "$1"
fi
}
alias myip="dig +short myip.opendns.com @resolver1.opendns.com"
# Clever auto checkout of your most used repos
# Uses grealpath from coreutils (brew install coreutils && brew link coreutils)
if [ -f /usr/bin/realpath ]; then
alias grealpath="realpath -s"
fi
function cd() {
GITHUB_ROOT="$HOME/github"
NPM_ROOT="$HOME/npm"
if [[ "$1" == "-P" ]]; then
builtin cd -P "$1" || return
fi
if [[ "$1" == "-" ]]; then
builtin cd - || return
return
fi
dir="$(grealpath -m "${1:-$HOME}")"
if [[ "$dir" = $GITHUB_ROOT/* ]]; then
repo="${dir#$GITHUB_ROOT/}"
repo_dir="$GITHUB_ROOT/${repo%%/*}"
[[ -d "$repo_dir" ]] || git clone "https://github.com/github/$repo" "$repo_dir"
fi
if [[ "$dir" = $NPM_ROOT/* ]]; then
repo="${dir#$NPM_ROOT/}"
repo_dir="$NPM_ROOT/${repo%%/*}"
[[ -d "$repo_dir" ]] || git clone "https://github.com/npm/$repo" "$repo_dir"
fi
builtin cd "$dir"
}
## Use SvelteKit to bootstrap a new svelte project and kickstart it.
function svelte-me() {
npm init svelte@next "$1"
cd "$1" || exit
npm install
git init
git add -A
git commit -m "Initial commit"
code .
npm run dev -- --open
}
function colormap() {
for i in {0..255}; do
printf "\x1b[38;5;${i}mcolour${i}\n"
done
}
function cscode() {
if [ -z "$1" ]; then
echo "Usage: cscode -r github_repo_name [-b branch_name]"
return
fi
csname="$(gh cs create $@)"
gh cs code -c $csname
}
alias listening_on_my_mac="netstat -an -ptcp | grep LISTEN"
function nibbles() {
if [ ! -f "${GOPATH}/bin/nibbles" ]; then
go install github.com/gophun/nibbles@latest
else
$GOPATH/bin/nibbles
fi
}
# Useful for accessing keychain when working remotely
alias keychain_login="security -v unlock-keychain ~/Library/Keychains/login.keychain-db"
# 1Password CLI
alias oplogin="eval \$(op signin --account my)"
# Docker for Mac does not listen on TCP by default
alias docker_tcp_listener="socat TCP-LISTEN:2376,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock &"