-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc.mine
262 lines (213 loc) · 5.36 KB
/
rc.mine
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/false
# shellcheck shell=sh
# shell-neutral rc settings
this="${BASH_SOURCE:-"$0"}"
DIR="$(cd "$(dirname "$this")"; pwd)"
[ `uname` = "Linux" ] && alias ls="ls --color=auto"
alias ll="ls -l"
alias lla="ls -la"
alias ccc="xclip -sel clipboard"
alias vvv="xclip -sel clipboard -o"
alias vman="MANPAGER='vim +MANPAGER -c \"set nomodifiable readonly\" -' man"
alias gvman="MANPAGER='gvim +MANPAGER -c \"set nomodifiable readonly\" -' man"
export PATH="$HOME/.local/bin":"$HOME/.local/usr/bin":"$HOME/.local/share/bin":"$PATH"
export PATH="$HOME/.dotnet/tools":"$PATH"
export PATH=.:"$PATH"
# EDITOR is used by tmux to infer if vi-mode should be used
# So try to set it
if command -v vim >/dev/null; then
export EDITOR=`command -v vim`
elif command -v vi >/dev/null; then
export EDITOR=`command -v vi`
fi
# readline to treat those as words:
# https://stackoverflow.com/a/11200998/695964
export WORDCHARS='"*?_-.[]~=&;!#$%^(){}<>|'"'"
# xterm does support truecolor (https://tintin.mudhalla.net/info/truecolor/),
# but doesn't advertise it by setting COLORTERM. This affects some mc themes
# (e.g. seasons-*). So we set it if in xterm.
[ -n "$XTERM_VERSION" ] && export COLORTERM=truecolor
godo() {
eval "nohup $@ > /dev/null 2>&1 &"
}
set_dpi() {
dpi=$1
printf "Setting DPI to $dpi in ~/.Xresources.dpi\n"
echo "Xft.dpi:$dpi" > ~/.Xresources.dpi
printf "Reloading ~/.Xresources\n"
xrdb -cpp `which cpp` ~/.Xresources
printf "done\n"
}
RES_MBP=1680x1050
RES_ACER_HOME=2560x1440
clip_dump() {
printf "\n======== clipboard =========\n"
xclip -o -sel clipboard
printf "\n======== primary =========\n"
xclip -o -sel primary
printf "\n"
printf "\n======== secondary =========\n"
xclip -o -sel secondary
printf "\n"
printf "\n======== buffer-cut =========\n"
xclip -o -sel buffer-cut
printf "\n"
}
# Fuzzy search in bookmarks
bm() {
type="$1";shift
case "$type" in
d) target="$HOME/.bookmarks/dirs";;
f) target="$HOME/.bookmarks/files";;
*) target="$HOME/.bookmarks";;
esac
find -L "$target" -type f ! -name '*~' | while read -r fn; do
cat $fn | while read -r ln; do
eval echo $ln
done
done | uniq | fzf
}
cdbm() {
cd `bm d`
}
_fzf_complete_fc() {
_fzf_complete --tac --cycle --prompt='fc> ' -- "$@" < <(fc -l -1000)
}
_fzf_complete_fc_post() {
awk '{print $1}'
}
[ -n "$BASH" ] && complete -F _fzf_complete_fc -o default -o bashdefault fc
logout_mac() {
launchctl bootout gui/$( id -u $(whoami) )
}
mkpost() (
USAGE="$(cat <<'EOF'
mkpost [-t title] [-f]
-t: use `title` in the directory/file name
-f: do not create directory, just a file
EOF
)"
while getopts 't:hf' opt; do
case "$opt" in
t)
title="$OPTARG";;
f)
create_file=1;;
h|*)
echo "$USAGE" >&2; exit 0;;
esac
done
shift $((OPTIND-1))
if test -z "$title"; then
printf "Title: "
read -r title
fi
if test -z "$title"; then
echo "Must give a title" >&2
exit 1
fi
ts="$(date +"%Y-%m-%d")"
name="$ts-$title"
if test -z "$create_file"; then
mkdir -p "$name"
fn="$name/post.md"
else
fn="$name.md"
fi
test -e "$fn" || {
echo "Creating file: $fn"
touch "$fn"
}
echo "Editing file: $fn"
"${EDITOR:-vim}" "$fn"
)
# This significantly slows down startup
### # Recipes
### {
### . "$DIR"/lib/recipe
### recipe_source_dir
### } >/dev/null 2>&1
dt() {
date +%Y%m%d:%H%M%S
}
# {{{ RECIPE V2
path_add() {
: "${1:?dir to be added}"
PATH="$PATH":"$(realpath "$1")"
}
path_rm() {
PATH="${PATH%:*}"
}
recipe_alias() {
: "${1:?dir to be added}"
find "$1" -type f -or -type l | while read -r fn; do
fn2="${fn#"$1"}"
alias_name="$(echo "${fn2#/}" | tr '/' ',')"
echo "r,$alias_name"="$(realpath "$fn")"
alias "r,$alias_name"="$(realpath "$fn")"
done
}
# }}}
getpath() (
/bin/sh -s -- "$@" <<'GETPATH'
unset OPTIND
USAGE="$(cat <<EOF
getpath [-t <type>] <path>
where type: scp
EOF
)"
while getopts 'ht:' opt; do case "$opt" in
t) type="$OPTARG" ;;
h|*) echo "$USAGE" >&2; exit 1 ;;
esac done
shift $((OPTIND-1))
path="$1"
case "$type" in
scp|*)
rpath="$(realpath "$path")"
rhome="$(realpath "$HOME")"
echo "scp://$(hostname)/~$(whoami)/${rpath##$rhome}"
;;
esac
GETPATH
)
goog() (
/bin/sh -s -- "$@" <<'GOOG'
USAGE="$(cat <<EOF
goog [-i] <term>
-i: I'm feeling lucky
EOF
)"
while getopts 'hi' opt; do case "$opt" in
i) lucky=1 ;;
h|*) echo "$USAGE" >&2; exit 1 ;;
esac done
shift $((OPTIND-1))
term="${@:?search term}"
url="google.com/search?q=${term}"
[ -n "$lucky" ] && url="${url}&btnI=1"
w3m "$url"
GOOG
)
alias googi="goog -i"
alias posix="googi posix"
ircsend() {
USAGE="$(cat <<EOF
$(basename "$0") [-h] -m msg
EOF
)"
while getopts 'hm:' opt; do case "$opt" in
m) MSG="$OPTARG" ;;
h|*) echo "$USAGE" >&2; return 1 ;;
esac done
shift $((OPTIND-1))
: "${MSG:?}"
set -x
nc irc.libera.chat 6667 <<EOF
nick klunotif
user klunotif . . .
privmsg klu :$MSG
quit bye
EOF
}
# vim: ft=sh fdm=marker