-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.shell-aliases
236 lines (163 loc) · 7.33 KB
/
.shell-aliases
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# vim: ft=bash
export SHORTHOSTNAME=`hostname | cut -d"." -f 1`
export OS=`uname -s | tr A-Z a-z`
export OS_DARK_MODE=$(2>/dev/null defaults read -g AppleInterfaceStyle > /dev/null && echo "true" || echo "false" )
function _hasFile() { if [ -e "$1" ]; then return 0; fi; return 1; }
function _hasNotFile() { if [ -e "$1" ]; then return 1; fi; return 0; }
function _hasFolder() { if [ -d "$1" ]; then return 0; fi; return 1; }
function _hasCmd() { which "$1" &>/dev/null; }
function _isMacOS() { uname -s | grep "Darwin" > /dev/null; }
function _isLinux() { uname -s | grep "Linux" > /dev/null; }
export TH_PROJECTS_FOLDER="$HOME/Developer"
# Commonly used programs
export HOMEBREW_NO_ANALYTICS=1
export FUNCTIONS_CORE_TOOLS_TELEMETRY_OPTOUT=1
export HOMEBREW_CASK_OPTS="--no-quarantine --require-sha"
function brew-forget() { rm -rfv "/usr/local/Caskroom/$1"; }
# Path configuration
# Reminder: Don't use tilde in paths
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH
export PATH="$PATH:$HOME/.local/bin/"
export PATH="$HOME/.dotfiles-externals/git-fuzzy/bin:$PATH"
export PATH="$PATH:$HOME/Library/Application Support/JetBrains/Toolbox/scripts"
export PATH="$PATH:$HOME/.scripts/"
export PATH="/opt/homebrew/bin:$PATH"
_hasFolder ~/.stew && export PATH="$HOME/.stew/bin:$PATH"
_isLinux && export BROWSER="firefox"
#_isMacOS && export BROWSER="open"
export EDITOR='vim'
export LC_ALL='en_US.UTF-8'
# Fine-tuning basic Unix commands
alias ...='cd ../..'
alias ..='cd ..'
alias KILL='sudo kill -9'
alias RM='rm -Rfv'
alias rm-empty-folders='find . -type d -empty -delete'
alias plz="sudo !!"
alias cp='cp -v'
alias df='df -h'
alias dud='du -h -d 1'
alias grep='grep --color'
alias halt='sudo halt'
alias l='ls -lh'
alias ll='l -ltr'
alias la='ls -lha'
alias mv='mv -v'
alias reboot='sudo reboot'
git-cosh() { git commit $1 -m "$2"; git push; }
git-submodule-rm() { git submodule deinit -f "$1"; git rm -f "$1"; rm -rf .git/modules/$1; }
git-ROLLBACK() { git fetch origin; git reset --hard origin/master; git clean -fdx; }
git-head-stat() { pushd $1 > /dev/null ; git log --oneline | head -n 1; popd > /dev/null; }
git-stat-folder() { [ -d "$1" ] && printf " %-9s @ %s\n" "$1" "$(git-head-stat $1)"; }
alias g='git'
alias gk='gitk --all'
alias gs='git s'
alias gca='git commit --ammend'
alias gb='git branch -v && git remote show origin'
alias gru='git remote update'
alias gp='git pull --rebase origin'
export FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -g ""'
alias vim-vimwiki='pushd "$TH_PROJECTS_FOLDER/vimwiki"; vim -u ~/.config/vim/vimwiki/vimrc; popd'
alias vimwiki="vim-vimwiki"
alias vim-writer='vim -u $HOME/.config/vim/writer/vimrc'
alias vim-doc=vim-writer
alias dotfiles='git --git-dir=$HOME/.dotfiles-bare-repo/ --work-tree=$HOME/'
alias dotfiles-private='git --git-dir=$HOME/.dotfiles-private-bare-repo/ --work-tree=$HOME/'
alias dotfiels='dotfiles'
alias dotifles='dotfiles'
alias .f='dotfiles'
alias .fp='dotfiles-private'
alias .fe='export GIT_DIR=$HOME/.dotfiles-bare-repo; export GIT_WORK_TREE=$HOME/; vim -c "GFiles"; git status; unset GIT_DIR; unset GIT_WORK_TREE'
alias motd="source $HOME/.shell-motd"
# Tiny tools
alias rmEmtpyFolders='find . -type d -empty -exec rmdir "{}" \;'
alias rmdsstore="find . -name '*.DS_Store' -type f -delete"
alias rmsvn="find . -name '*.svn' -type f -delete"
alias noftchcks="du -akx | sort -nr | less"
alias mvn-upgrade='mvn versions:use-next-releases'
alias java-list-imports='find . -iname "*.java" | xargs cat | grep -e "^import" | sort -r | uniq'
# http://www.open-source-blog.de/2014/11/17/apple-spezifische-dateien-wie-appledouble-ds_store-etc-loeschen-mittels-find/
rm-macos-temp-files() { find \( -name ".AppleDouble" -or -name ".DS_Store" -or -name ".Trashes" -or -name "._*" -or -name ".TemporaryItems" \) -execdir rm -Rv {} \;; }
# Third party commands
alias gentlecp='rsync --update --progress --human-readable'
alias screen="screen -t \""$SHORTHOSTNAME" - Escape key is CTRL+y - scroll via escape+ESC\""
customboat() {
local XDG_CONFIG_HOME="$HOME/.config/newsboat/$1/"
local XDG_DATA_HOME="$HOME/.local/share/newsboat/$1/"
local DB_VAULT="$HOME/Cloud/OneDrive/newsboat/"
# security add-generic-password -a $LOGNAME -s newsboat -w *********
#local password=$(security find-generic-password -w -a "$LOGNAME" -s newsboat)
#7z e "$DB_VAULT/$1.7z" -o"$XDG_DATA_HOME/newsboat/" -aos -mhe=on -p"$password" || return
XDG_CONFIG_HOME="$XDG_CONFIG_HOME" XDG_DATA_HOME="$XDG_DATA_HOME" newsboat; stty sane || return
#7z u "$DB_VAULT/$1.7z" "$XDG_DATA_HOME/newsboat/cache.db" -mx4 -mhe=on -p"$password"
#rm "$XDG_DATA_HOME/newsboat/cache.db"
}
alias news='customboat "news"'
#alias news="XDG_CONFIG_HOME=\"$HOME/.config/newsboat/news/\" XDG_DATA_HOME=\"$HOME/.local/share/newsboat/news/\" newsboat"
alias tv='customboat "tv"'
#alias tv="XDG_CONFIG_HOME=\"$HOME/.config/newsboat/tv/\" XDG_DATA_HOME=\"$HOME/.local/share/newsboat/tv/\" newsboat"
# Shortcuts
function take() { mkdir -p "$1" && cd "$1"; }
function t() { mkdir -p "$HOME/temp" && cd "$HOME/temp"; }
alias d="cd ~/Documents"
alias dl="cd ~/Downloads"
alias p="cd $TH_PROJECTS_FOLDER"
alias add-url-to-diary="~/.config/newsboat/scripts/vimwiki"
function apple-app-id() { osascript -e 'id of app "'$1'"'; }
ls-extended() { ls -lart; }
alias exa="eza"
_hasCmd "eza" && ls-extended() {
eza --icons -l --sort=changed --hyperlink;
echo
gitcmd="git"
if [ "$PWD" = "$HOME" ]; then
gitcmd="git --git-dir=$HOME/.dotfiles-bare-repo/ --work-tree=$HOME/"
fi
if [ -d "$PWD/.git" ] || [ "$PWD" = "$HOME" ]; then
eval "${gitcmd} status -s";
fi
}
_hasCmd "eza" && alias l='ls-extended'
# Load OS specific bash settings
source-if-exist() { [[ -e $1 ]] && source "$1"; }
# Load Host specific bash settings
source-if-exist "${BASH_SOURCE[0]}.$SHORTHOSTNAME"
function inc-install() {
npx google-artifactregistry-auth ~/.npmrc
npm install $@
}
function b64D() {
echo $1 | base64 --decode
}
source-if-exist "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc"
# Change directory to current Finder window
# https://stackoverflow.com/questions/420456/open-terminal-here-in-mac-os-finder#answer-7098442
cf() {
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')"
}
# https://medium.com/better-programming/boost-your-command-line-productivity-with-fuzzy-finder-985aa162ba5d
# find-in-file - usage: fif <SEARCH_TERM>
fif() {
if [ ! "$#" -gt 0 ]; then
echo "Need a string to search for!";
return 1;
fi
rg --files-with-matches --no-messages "$1" | fzf $FZF_PREVIEW_WINDOW --preview "rg --ignore-case --pretty --context 10 '$1' {}"
}
# Linux: add Homebrew to the PATH
_hasFile /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# Kitty
alias kitty-colors-reset='kitty @ set-colors --reset'
alias kitty-colors-white='kitty @ set-colors --all --configured ~/.config/kitty/white-theme.conf'
# Kubectl
_hasFolder "${HOME}/.kube" && export KUBECONFIG=$(find ~/.kube/kubeconfigs -type f ! -name '.*' -print0 | xargs -0 echo | tr ' ' ':')
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
alias k="kubectl"
# Declare everything in Golang as private, https://sourcehut.org/blog/2023-01-09-gomodulemirror/
export GOPRIVATE=*
# Lazy load nvm, based on https://medium.com/@dannysmith/little-thing-2-speeding-up-zsh-f1860390f92
nvm() {
unset -f nvm
source $(brew --prefix nvm)/nvm.sh && nvm "$@"
}