-
Notifications
You must be signed in to change notification settings - Fork 2
/
.zshrc
86 lines (70 loc) · 1.82 KB
/
.zshrc
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
# Oh My Zsh configuration
export ZSH="$(realpath ~/.oh-my-zsh)"
ZSH_THEME="agnoster"
plugins=(git)
source $ZSH/oh-my-zsh.sh
# Other scripts
## Machine-specific stuff that I don't want to sync
if [[ -f ~/.localzshrc ]]; then
. ~/.localzshrc
fi
## z.sh (unrelated to zsh) to go fast
if [[ -f ~/dotfiles/z.sh ]]; then
. ~/dotfiles/z.sh
else
echo "z.sh or $(realpath ~/dotfiles) doesn't exist. Make sure dotfiles is" \
"in your home dir, and that z.sh is in it."
fi
# Options
if type nvim >/dev/null 2>/dev/null; then
export EDITOR=nvim
alias vim=nvim
else
export EDITOR=vim
fi
## Sharing history between zsh processes
setopt INC_APPEND_HISTORY
setopt SHARE_HISTORY
## Never ever beep ever >:(
setopt NO_BEEP
## Allow tab completion in the middle of a word
setopt COMPLETE_IN_WORD
# Aliases and functions
## General
up() {
if [ -z "$1" ]; then
up 1
else
cd $(yes ".." | head "-$1" | tr '\n' '/')
fi
}
## Vimwiki/Notes
diary () {
today=~/notes/diary/$(date "+%Y-%m-%d.wiki")
if [ "$EDITOR" = "vim" ] || [ "$EDITOR" = "nvim" ] && [ ! -s "$today" ]
then
# Insert a date at the top
# Note that this assumes that if (n)vim is available, then my dotfiles
# are already set up.
"$EDITOR" -c "normal ,d" "$today"
else
"$EDITOR" "$today"
fi
}
### qn (QuickNote) - a dispoable note made in /tmp that is copied to clipboard
### after exiting.
qn() {
todaydir="/tmp/qn-$(date '+%Y-%m-%d')"
if [ ! -d "$todaydir" ]; then
mkdir "$todaydir"
fi
notepath="$todaydir/$(date +%s).wiki"
"$EDITOR" "$notepath"
case "$(uname -s)" in
Linux*) cmd='xclip -i -selection clipboard';;
Darwin*) cmd='pbcopy';;
*) exit 1
esac
echo "$cmd"
(cat "$notepath" 2>&1 2>/dev/null || ;) | eval "$cmd"
}