-
Notifications
You must be signed in to change notification settings - Fork 0
/
arch
65 lines (59 loc) · 2.36 KB
/
arch
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
which pacman >/dev/null || return 0
# Arch aliases
alias pac='noglob sudo pacman'
alias pacs='pac -Syu --needed'
alias pacr='pac -R --recursive'
alias yau='sudo systemctl start --show-transaction reflector && noglob yay'
alias yays='noglob yay -Sy --needed --noprovides'
alias yayr='noglob yay -R --cascade --recursive'
_yayre_params="-S --rebuild --noprovides --nodiffmenu --noconfirm"
# Reinstall given packages with all dependencies - https://www.reddit.com/r/archlinux/comments/33cety
yayre() {
yay $(echo $_yayre_params) --asdeps $(yay -Si "$@" | grep Depends | cut -d':' -f2) &&
yay $(echo $_yayre_params) "$@"
}
# Helper function to integrate yay and fzf
yzf() {
pos=$1
shift
sed "s/ /\t/g" |
fzf --nth=$pos --multi --history="${FZF_HISTDIR:-$XDG_STATE_HOME/fzf}/history-yzf$pos" \
--preview-window=60%,border-left \
--bind="alt-bspace:clear-query,double-click:execute(xdg-open 'https://archlinux.org/packages/{$pos}'),alt-enter:execute(xdg-open 'https://aur.archlinux.org/packages?K={$pos}&SB=p&SO=d&PP=100')" \
"$@" | cut -f$pos | xargs
}
# Dev note: print -s adds a shell history entry
# List installable packages into fzf and install selection
yas() {
# TODO also filter by provides field
cache_dir="/tmp/yas-$USER"
case "$1" in (-y*) rm -rf "$cache_dir"; shift; param=$1;; esac
mkdir -p "$cache_dir"
preview_cache="$cache_dir/preview_{2}"
list_cache="$cache_dir/list$*"
{ test "$(cat "$list_cache" | wc -l)" -lt 50000 && rm "$list_cache"; } 2>/dev/null
pkg=$(
( cat "$list_cache" 2>/dev/null ||
{ $(test $param && echo sudo) pacman --color=always -Sl $param "$@"; yay --color=always -Sl aur $param "$@" } |
sed 's/ [^ ]*unknown-version[^ ]*//' | tee "$list_cache" ) |
yzf 2 --tiebreak=chunk,index --preview="cat $preview_cache 2>/dev/null | grep -v 'Querying' | grep . || yay --color always -Si {2} | tee $preview_cache"
)
if test -n "$pkg"
then echo "Installing $pkg..."
cmd="yay -Sy --batchinstall --rebuildtree $pkg"
print -s "$cmd"
eval "$cmd"
rehash
fi
}
# List installed packages into fzf and remove selection
# Tip: use -e to list only explicitly installed packages
yar() {
pkg=$(yay --color=always -Q "$@" | yzf 1 --tiebreak=chunk,length --preview="yay --color always -Qli {1} | sed 's/^[^a-z]*m{1}//'")
if test -n "$pkg"
then echo "Removing $pkg..."
cmd="yay -R --cascade --recursive $pkg"
print -s "$cmd"
eval "$cmd"
fi
}