-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell_common
More file actions
185 lines (163 loc) · 4.8 KB
/
shell_common
File metadata and controls
185 lines (163 loc) · 4.8 KB
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
#!/bin/sh
PARTS=("/usr/local/bin"
"/usr/local/sbin"
"/opt/local/bin"
"/opt/local/sbin"
"$HOME/.local/bin")
for PART in "${PARTS[@]}"; do
if [[ -e $PART && ":$PATH:" != *":$PART:"* ]]; then
export PATH="$PART:$PATH"
fi
done
# prefer clang if available
if [ -n "$(command -v clang)" ]; then
export CC="$(which clang)"
fi
if [ -n "$(command -v clang++)" ]; then
export CXX="$(which clang++)"
fi
# cheapo virtualenvwrapper
unset -f activate 2>> /dev/null
function activate() {
ACTIVATE_SCRIPTS=(".venv/bin/activate"
".env/bin/activate"
"venv/bin/activate"
"env/bin/activate")
PROJ_DIR=$(git rev-parse --show-toplevel 2>/dev/null)
if [ $PROJ_DIR ]; then
PROJ_DIR="$PROJ_DIR/"
ACTIVATE_SCRIPTS+=("${PROJ_DIR}.venv/bin/activate"
"${PROJ_DIR}.env/bin/activate"
"${PROJ_DIR}venv/bin/activate"
"${PROJ_DIR}env/bin/activate")
fi
for ACTIVATE_SCRIPT in "${ACTIVATE_SCRIPTS[@]}"; do
if [ -f "$ACTIVATE_SCRIPT" ]; then
. "$ACTIVATE_SCRIPT"
return 0
fi
done
if [ -f 'poetry.lock' ] && [ -f 'pyproject.toml' ]; then
poetry shell
return 0
fi
echo 'No environment found to activate :('
return 1
}
# useful aliases
alias lt='ls -lth'
alias rsync='rsync -h --progress --partial'
alias gvir='gvim --remote'
alias tree='tree -I __pycache__'
alias mail-personal='mutt -F ~/.mutt/personal.muttrc'
alias feh='feh --magick-timeout 1 --geometry 500x500'
# prefer neovim
if [ -n "$(command -v nvim)" ]; then
alias vim=nvim
fi
# TODO: need to make this work on linux.
unset -f pman 2>> /dev/null
function pman() {
man -t "$@" | open -f -a Preview
}
# setup custom dir mapping tool
unset -f map 2>> /dev/null
function map() {
tree -a -J $1 | $HOME/.dotfiles/map.py | dot -Tpdf
}
# function to open vim with fuzzy found file
# alias vf='vim $(fzf --height 30)'
unset -f vf 2>> /dev/null
function vf() {
f=$(fzf --height 30 --query "$*")
if [ $f ] && [ -f $f ]; then
vim $f
fi
}
# function to git diff with fzf to pick a file
unset -f gdf 2>> /dev/null
function gdf() {
f=$(fzf --height 30 --query "$*")
if [ $f ] && [ -f $f ]; then
git diff $f
fi
}
# function to git add with fzf to pick a file
unset -f gaf 2>> /dev/null
function gaf() {
f=$(fzf --height 30 --query "$*")
if [ $f ] && [ -f $f ]; then
git add $f
fi
}
unset -f glf 2>> /dev/null
function glf() {
lbranch=$(git branch -vv | grep '*' | cut -d' ' -f2)
rbranch=$(git branch -vv | grep '*' | awk -F'[\\[\\]]' '{print $2}')
remote=$(git branch -vv | grep '*' | awk -F'[\\[\\]]' '{print $2}' | cut -d'/' -f1)
while true; do
printf "Force reset $lbranch to match $rbranch? (y/N): " >&2
read -r yn
case $yn in
[Yy]* ) echo "Fetching and resetting..."; break;;
* ) echo "Aborting, no changes made!"; return;;
esac
done
git fetch $remote
git reset --hard $rbranch
}
# function to open with fuzzy found file
unset -f of 2>> /dev/null
function of() {
f=$(fzf --height 30 --query "$*")
if [ $f ] && [ -f $f ]; then
open $f
fi
}
# function to countdown the provided seconds
# ex: `countdown $((5*60))` to countdown for 5 minutes
unset -f countdown 2>> /dev/null
function countdown() {
t=$((`date +%s` + $1))
while [ "$t" -gt `date +%s` ]; do
echo -en "\r\033[K$(($t - `date +%s`))"
sleep 0.1
done
if [ "$(uname)" = "Darwin" ]; then
say -v Fred "Your $(printf "%'.0f" $1) second timer is done!"
fi
echo -e "\nDONE"
}
# make fzf use fd for searching file names
if [ -n "$(command -v fd)" ]; then
export FZF_DEFAULT_COMMAND='fd --type f'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
fi
# make ripgrep aware of configuration and set it up to use a pager
unset -f rg 2>> /dev/null
export RIPGREP_BIN=$(which rg 2>/dev/null)
export RIPGREP_CONFIG_PATH="$HOME/.ripgreprc"
function rg() {
$RIPGREP_BIN -p "$@" | less -RFX
}
# replace other search tools with ripgrep
alias ag='rg'
alias ack='rg'
# Don't close terminal on Ctrl+D
export IGNOREEOF=2
# Coloring on some systems for ls
# http://osxdaily.com/2012/02/21/add-color-to-the-terminal-in-mac-os-x/
export CLICOLOR=1
export LSCOLORS=GxfxcxdxbxAgAdabagacad
if [ $TERM = "screen" ]; then
export TERM=screen-256color
fi
# Make less not clear screen on exit (-X), exit if content fits (-F), and use
# colors (-R)
export LESS="-XFR"
export EDITOR=vim
# If there is stuff like API tokens, keys, etc that need to be put in the
# environment, put them in ~/.private_profile and this will source them in
if [ -s "$HOME/.private_profile" ]; then
source "$HOME/.private_profile"
fi