-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_commonrc.tmpl
More file actions
92 lines (78 loc) · 2.5 KB
/
dot_commonrc.tmpl
File metadata and controls
92 lines (78 loc) · 2.5 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
# this file is sourced by both zsh and bash; should use common syntax
if [ -n "$ZSH_VERSION" ]; then
autoload -Uz colors && colors
setopt promptsubst
autoload -Uz compinit && compinit
fi
# completions
if [ -n "$ZSH_VERSION" ]; then
eval "$(chezmoi completion zsh)"
else
eval "$(chezmoi completion bash)"
fi
# === ALIASES
alias c3="uv run --directory=$HOME/.local/share/pycalc3 ipython --no-banner -i --profile=default"
alias t3="uv run --directory=$HOME/.local/share/pycalc3 ipython --no-banner -i --profile=sympy"
alias "chomp=perl -pi -e 'chomp if eof'"
NCSU_HOSTS=(eos grendel hydra kraken)
for h in "${NCSU_HOSTS[@]}"; do
alias "ssh-$h=sshpass -f $HOME/.ssh/id_plaintext_ncstate ssh $h"
done
v() {
command "$VISUAL" "$@"
}
if [ -n "${ZSH_VERSION-}" ]; then
case "$VISUAL" in
*nvim) compdef v=nvim ;;
*vim) compdef v=vim ;;
esac
fi
ssh-privpub() {
for key in "$@"; do
[[ "$key" == *.pub ]] && continue
[ -f "$key" ] && ssh-keygen -y -f "$key" > "${key}.pub" 2>/dev/null && echo "${key}.pub"
done
}
[ -n "$ZSH_VERSION" ] && compdef _files ssh-privpub
reflink_duplicates() {
local dir="${1:-.}"
local cp_flags
case "$(uname -s)" in
Darwin) cp_flags="-cf" ;;
*) cp_flags="--reflink=always -f" ;;
esac
find-duplicates --keep-going "$dir" | jq -r '
to_entries[] |
.value[0] as $canonical |
.value[1:][] |
[$canonical, .] | @tsv
' | while IFS=$'\t' read -r canonical dup; do
echo "reflinking: $dup -> $canonical" >&2
cp $cp_flags -- "$canonical" "$dup"
done
}
if [ -n "$ZSH_VERSION" ]; then
compdef '_files -/' reflink_duplicates
fi
chezmoi-cd() {
cd "$(chezmoi source-path)"
}
bw-unlock() {
export BW_SESSION="$(bw unlock --raw)"
}
if [ "$(uname -o)" = "GNU/Linux" ]; then
# given a PID show all files that PID has open
filewatch() {
local pid=$1
watch -n 5 "PIDS=\$(ps --ppid $pid -o pid --no-headers 2>/dev/null | tr -d ' ' | paste -sd,),$pid; lsof -p \"\$PIDS\" -nP -F n 2>/dev/null | grep '^n/' | sed 's|^n||' | grep -Ev '^(/dev|/proc|/sys|/run|/tmp|/cgroup|/\$)' | grep -v '(stat:' | sort -ru"
}
fi
# === ANNOUNCEMENTS/psuedoMOTD
if [[ $- == *i* && -z ${DID_COMMONRC_SPLASH+x} ]]; then
LAST_SYNC="{{ now | date "2006-01-02" }}"
DAYS_OLD=$(( ( $(date +%s) - $(date -j -f "%Y-%m-%d" "$LAST_SYNC" +%s 2>/dev/null || date -d "$LAST_SYNC" +%s) ) / 86400 ))
if [ "$DAYS_OLD" -gt 7 ]; then
echo "warning: last chezmoi sync was $LAST_SYNC, resync soon" >&2
fi
fastfetch >&2
fi