-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.zsh
129 lines (109 loc) · 3.07 KB
/
functions.zsh
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
# dots
# Run the dotfiles script from anywhere
dots() {
cd "$DOTFILES" && ./install.sh $@
cd - >>/dev/null
}
# Read MarkDown
rmd() {
pandoc $1 | lynx -stdin
}
# Search and install from apt with fzf
# Optional argument to shorten search list
asp() {
local inst=$(apt-cache search "${1:-.}" | eval "fzf -m --header='[apt install]'")
if [[ $inst ]]; then
local name=$(echo $inst | head -n1 | awk '{print $1;}')
if [[ ! -z "$(apt list --installed 2>/dev/null | grep -e "^$name/")" ]]; then
echo -e "\e[1m$name\e[0m is alredy installed: (u)pdate or (r)emove [ENTER to cancel]: \c"
read option
if [[ $option == "u" || $option == "U" ]]; then
echo -e "\e[1mUpgrading: \e[1;94m$inst\e[0m \n"
sudo apt install $name
elif [[ $option == "r" || $option == "R" ]]; then
echo -e "\e[1mRemoving: \e[1;94m$inst\e[0m \n"
sudo apt remove $name
fi
else
echo -e "\e[1mInstalling: \e[1;94m$inst\e[0m \n"
sudo apt install $name
fi
fi
}
psp() {
pacman -Slq | fzf --multi --preview 'pacman -Si {1}' | xargs -ro sudo pacman -S
}
ysp() {
yay -Ss $1 --color=always \
| sed -n '1~2p' \
| fzf --tac --ansi --multi --preview 'yay -Si {1}' \
| cut -d" " -f1 | xargs -ro yay -S
}
# rg - less
# pipe rg to less to not spam terminal buffer
rgl() {
rg $@ -p --line-buffered | less -R
}
# Testing truecolor support
truecolors() {
awk -v term_cols="${width:-$(tput cols || echo 80)}" 'BEGIN{
s="/\\";
for (colnum = 0; colnum<term_cols; colnum++) {
r = 255-(colnum*255/term_cols);
g = (colnum*510/term_cols);
b = (colnum*255/term_cols);
if (g>255) g = 510-g;
printf "\033[48;2;%d;%d;%dm", r,g,b;
printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
printf "%s\033[0m", substr(s,colnum%2+1,1);
}
printf "\n";
}'
}
# Yubikey reload. Will tell gpg-agent to update key ids when using multiple yubikeys with identical
# gpg keys.
# Run this when switching yubikey
ykr() {
gpg-connect-agent "scd serialno" "learn --force" /bye
echo UPDATESTARTUPTTY | gpg-connect-agent
}
# GitHub
ghc() {
# Original author: Sebastian Jambor (https://github.com/sgrj)
# Original source retrieved from: https://seb.jambor.dev/posts/improving-shell-workflows-with-fzf/
local jq_template pr_number
jq_template='"'\
'#\(.number) - \(.title)'\
'\t'\
'Author: \(.user.login)\n'\
'Created: \(.created_at)\n'\
'Updated: \(.updated_at)\n\n'\
'\(.body)'\
'"'
if [ -n "$1" ]; then
pr_number="$1"
else
pr_number="$(
gh api 'repos/:owner/:repo/pulls' |
jq ".[] | $jq_template" |
sed -e 's/"\(.*\)"/\1/' -e 's/\\t/\t/' |
fzf \
--with-nth=1 \
--delimiter='\t' \
--preview='echo -e {2}' \
--preview-window=top:wrap |
sed 's/^#\([0-9]\+\).*/\1/'
)"
fi
if [ -n "$pr_number" ]; then
gh pr checkout "$pr_number"
fi
}
dotcomp() {
_dotnet_zsh_complete()
{
local completions=("$(dotnet complete "$words")")
reply=( "${(ps:\n:)completions}" )
}
compctl -K _dotnet_zsh_complete dotnet
}