-
Notifications
You must be signed in to change notification settings - Fork 1
/
yashrc
105 lines (91 loc) · 3.34 KB
/
yashrc
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
# if yash is built with line-editing enabled...
if command --identify --builtin-command bindkey >/dev/null; then
# print job status update ASAP, but only while line-editing
set --notify-le
# some terminfo data are broken; meta flags have to be ignored for UTF-8
set --le-no-conv-meta
# I'll try emacs mode
set --emacs
fi
# arrange history
set --hist-space
HISTFILE=~/.yash_history
HISTSIZE=50000
HISTRMDUP=50000
# Get ourselves a nice prompt
ks() { s="$?" ; $* ; return "$s" ; }
prompt_git() {
porcelain="$(git status --branch --porcelain 2>/dev/null)"
if test "$?" = 0; then
local branch="$(printf '%s' "$porcelain" | sed -n 's/\.\.\..*//;1s/## //p')"
local behind="$(printf '%s' "$porcelain" | sed -n '1s/## .*behind \([0-9]*\).*/-\1/p')"
local ahead="$(printf '%s' "$porcelain" | sed -n '1s/## .*ahead \([0-9]*\).*/+\1/p')"
local status="$({ echo OK; printf '%s' "$porcelain" | sed '/##/d;s/\(..\).*/\1/'; } | tail -1)"
echo " (${branch}${behind}${ahead}|${status})"
fi
}
prompt_pwd() {
pwd | sed -e "s_${HOME}_~_" -e 's_\(/*\.*.\)[^/]*/_\1/_g'
}
prompt_agent() {
[ -z "$SSH_AGENT_PID" ] || echo " (A)"
}
prompt_status() {
if [ "$?" = "0" ]
then echo "$"
else echo "%"
fi
}
prompt_date() {
date +%H:%M:%S
}
prompt_mail() {
unread="$(mlist -nds $(mdirs /data/mail) | wc -l)"
[ "$unread" -eq 1 ] && printf ' (1 mail)'
[ "$unread" -gt 1 ] && printf ' (%s mails)' "$unread"
}
BOLD="\fo."
GREEN="\fg."
RESET="\fD."
PS1="$BOLD[\$(ks prompt_date)]$RESET $GREEN\$(ks prompt_pwd)$RESET\$(ks prompt_git)\$(ks prompt_agent)\$(ks prompt_mail) \$(prompt_status) "
unset BOLD
unset GREEN
unset RESET
# Color ls
alias ls="ls --color=auto"
alias ll="lr -Fl1Ghov"
# Email
alias marchive="mflag -fSt"
alias mspam="mflag -fST"
alias mkeep="mflag -FSt"
alias munread="mdirs /data/mail | mlist -nds | mseq -S && mscan"
alias minbox="mdirs /data/mail | mlist -ndt | mpick -t 'flagged || ! seen' | msort -d | mthread | mseq -S && mscan | sed 's/^\(...\)\(...\) \(..........\) \(.................\) \(.*\)$/$(tput setaf 119)\1$(tput sgr0)\2 $(tput setaf 8)\3$(tput sgr0) \4 $(tput setaf 148)\5$(tput sgr0)/'"
export MBLAZE_PAGER='less -RF'
# There is only one vis
alias vim="vis"
alias vi="vis"
alias nano="vis"
# Ready for ssh'ing
alias agent='eval "$(ssh-agent)" && ssh-add'
alias unlock='gpg-connect-agent <<<bye'
alias weechat="ssh -t weechat@Hetzner abduco -A weechat"
alias agenda="khal list today 7d"
# Ledger
alias haccounts="hledger -I --alias '/.*:Accounts [^:]*:(.*)/=Accounts:\1' bal accounts"
alias ladd='ladd -a /data/documents/ledger/2021/main.journal /data/documents/ledger/*/main.journal'
alias iadd='iadd /data/documents/ledger/2021/main.journal'
alias is='hledger is -b $(date -d "7 months ago" +%Y-%m) -e $(date +%Y-%m) -MTA --tree -2'
alias cf='hledger cf -b $(date -d "7 months ago" +%Y-%m) -e $(date +%Y-%m) -MTA --tree -2'
alias bs='hledger bs not:accounts'
# Rust debugging
alias rustdb="RUST_TEST_THREADS=1 RUST_GDB=cgdb rust-gdb"
alias rtdb='rustdb $(cargo test -v 2>&1 | grep "Running.*$(pwd)" | cut -f2 -d"\`")'
go() {
dir="$(lr /home /data /etc -t '(name ~~ ".*" && prune || print) && type = d && !(name = ".git")' \
| sk --height 10 \
)"
[ -n "$dir" ] && cd "$dir" || false
}
terminfo() {
infocmp -x | ssh $@ 'cat > $TERM.info && tic -x $TERM.info && rm $TERM.info'
}