-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zsh_profile
211 lines (185 loc) · 5.07 KB
/
.zsh_profile
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
export PATH="$HOME/bin:/usr/local/bin:$PATH:/opt/homebrew/bin"
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell" # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
source $ZSH/oh-my-zsh.sh
plugins=(git)
export EDITOR="vi"
export GOPATH="$HOME/gopath"
if test -f ~/.nvmrc; then
source ~/.nvmrc
fi
if test -f ~/.localrc; then
source ~/.localrc
fi
function http {
use_help="http {COMMAND:repo,pulls,wat,ai,<url>} [ARGUMENT:<query>,<path>]\n __\n"
cmd_help="repo|open current repo's gh remote\n pulls|alias for 'http repo pulls'\n wat|query duckduckgo\n ai|query chatgpt (requires session)\n py|serve local path with python\n <url>|open with browser\n help|this message\n __\n"
arg_help="query|query for wat or ai cmd\n path|path to append to url (eg 'pulls')\n __\n"
all_help="
Usage
$use_help
Command
$cmd_help
Argument
$arg_help
"
cmd="${1}"
arg="${2}"
url_base=""
url_path=""
scr_sesh=false
scr_name="http-func-screen-sesh"
if test -z "${cmd}"; then
cmd="help"
elif [[ "${cmd}" == "pulls" ]]; then
cmd="repo"
arg="pulls"
elif [[ "${cmd}" == "pr" ]] && ! test -z "${arg}"; then
cmd="repo"
arg="pull/${arg}"
fi
if ! test -z "${arg}"; then
url_path="${arg}"
fi
if [[ "${cmd}" == "help" ]]; then
echo -e "$all_help" | column -s "|" -t
return 1
elif [[ "${cmd}" == "repo" ]]; then
url_base="$(git remote -v | grep origin | tail -1 | awk '{print $2}' | sed 's/.git//g' | awk -F ':' '{print "https://github.com/"$2}')/"
elif [[ "${cmd}" == "wat" ]]; then
url_base="https://duckduckgo.com/"
elif [[ "${cmd}" == "bot" ]] || [[ "${cmd}" == "computer" ]] || [[ "${cmd}" == "ai" ]]; then
url_base="https://chat.openai.com/?q="
elif [[ "${cmd}" == "py" ]]; then
url_base="http://localhost:8000/"
if test -z "${arg}"; then
http_dir="."
elif test -f "${arg}"; then
http_dir="$(dirname $arg)"
url_path="$(basename $arg)"
elif test -d "${arg}"; then
http_dir="${arg}"
fi
if screen -S "$scr_name" -L -d -m python3 -m http.server --directory "$http_dir"; then
scr_sesh=true
sleep 3
else
echo "screen failed"
pkill "screen"
return 1
fi
elif [[ "${cmd}" == "pr" ]]; then
gh pr create --fill
gh pr view --web
else
url_base="https://${cmd}/"
fi
url="${url_base}${url_path}"
echo "--> ${url}"
/usr/bin/open "${url}"
if $scr_sesh; then
echo "attaching python server screen session..."
if ! screen -A -d -r "$scr_name"; then
echo "Error: screen session failed to start!"
cat screenlog.0
rm -f "screenlog.*"
return 1
fi
rm -f "screenlog.*"
pkill screen
return 0
fi
}
function venvter {
venvf=".venv/bin/activate"
msg="type source loaded?\n---- ------ -------"
msg="$msg\nvenv ${venvf}"
if source $venvf &> /dev/null; then
msg="$msg ✅"
else
msg="$msg ❌"
fi
if test -z "$1"; then
envf=""
else
envf="${1}"
fi
if test -z $envf || ! test -f $envf; then
envf="${envf}.env"
fi
msg="$msg\n.env $envf"
if source $envf &> /dev/null; then
msg="$msg ✅"
else
msg="$msg ❌"
fi
echo -e "$msg" | column -t
}
ssh_port_forward() {
# Usage: ssh_port_forward [port] [intermediate_host] [target_host]
# Assign arguments to variables
PORT=$1
INTERMEDIATE_HOST=$2
TARGET_HOST=$3
# Check if all arguments are provided
if [ -z "$PORT" ] || [ -z "$INTERMEDIATE_HOST" ] || [ -z "$TARGET_HOST" ]; then
echo "Usage: ssh_port_forward [port] [intermediate_host] [target_host]"
return 1
fi
# SSH command with port forwarding
ssh -L ${PORT}:localhost:${PORT} ${INTERMEDIATE_HOST} ssh -L ${PORT}:localhost:${PORT} ${TARGET_HOST}
}
melatonin() {
pid=
screen -S "melatonin" -L -d -m caffeinate -d -w $pid
rm -f screenlog.*
}
decaffeinate() {
if pgrep -i caffeinate; then
pkill -i caffeinate || sudo pkill -i caffeinate
fi
}
χασίσι() {
if test -z $3; then
t=$3
else
t=5
fi
case "$1" in
as)
caffeinate -uid "$2" -t $t
;;
til)
pid=$(pgrep -u $(id -u) -o -x -i "$2")
caffeinate -uid -w $pid -t $t
;;
*)
rm -rf $HOME/.pwr && mkdir $HOME/.pwr || mkdir $HOME/.pwr
echo -e "#!/bin/bash\nwhile true; do echo '' && cat ~/.hitchhikerrc | jq '.[] | .quote' | shuf -n 39 | head -1 | tr -d '\"' | cowsay -r -C && sleep 92 || exit 1; done\n" > $HOME/.pwr/icu.creepin
chmod +x $HOME/.pwr/icu.creepin
caffeinate -uid "$HOME/.pwr/icu.creepin"
;;
esac
}
psaux() {
if test -z $1; then
ps aux
elif [[ "$1" == "grep" ]]; then
ps aux | grep -i "$1"
else
ps aux | grep -i "$1" | grep -v grep
fi
}
alias wip="git commit -m 'wip'"
alias wipush="wip && git push"
alias wippit="git add . && wipush"
alias venv="rm -rf .venv; mkdir .venv && virtualenv -p $(which python3.11) .venv && venvter"
alias mip="git commit -m 'merge'"
alias black="python3 -m black"
alias ohmyzsh="mate ~/.oh-my-zsh"
alias unixtime="date +'%s'"
alias repo="http repo"
alias pulls="http pulls"
alias pr="http pr"
alias last="echo $?"
alias x=χασίσι