TheRepoClub-DotFiles/localbin/.local/bin/pacsync

120 lines
3.0 KiB
Plaintext
Raw Normal View History

2022-10-21 02:27:25 -04:00
#!/usr/bin/env bash
2022-10-25 02:07:52 -04:00
#-*-coding:utf-8 -*-
#Auto updated?
# Yes
#File:
# pacsync
#Author:
# The-Repo-Club [wayne6324@gmail.com]
#Github:
# https://github.com/The-Repo-Club/
#
#Created:
# Tue 25 October 2022, 07:04:14 AM [GMT+1]
#Modified:
2022-10-30 08:48:36 -04:00
# Sun 30 October 2022, 12:46:18 PM [GMT]
2022-10-25 02:07:52 -04:00
#
#Description:
2022-10-27 17:43:30 -04:00
# FZF menu for pacman yay or pikaur
2022-10-25 02:07:52 -04:00
#
#Dependencies:
2022-10-27 17:43:30 -04:00
# bash, pacman, yay, pikaur
2022-10-25 02:07:52 -04:00
#
2022-10-30 08:48:36 -04:00
# shellcheck disable=all
2022-09-05 12:16:33 -04:00
2022-10-30 08:48:36 -04:00
colorize() {
local string
string="${1//\[/\\033\[0;32m\[}"
string="${string//\]/\]\\033\[0m}"
echo -n -e "${string}"
2022-09-05 12:16:33 -04:00
}
2022-10-30 08:48:36 -04:00
CP_KEY="ctrl-p"
CA_KEY="ctrl-a"
CI_KEY="ctrl-i"
CQ_KEY="ctrl-q"
TP_KEY="ctrl-t"
HEADER=$(colorize "[ENTER] Install selected [${TP_KEY^^}] Toggle preview
[${CP_KEY^^}] Pacman [${CA_KEY^^}] AUR [${CI_KEY^^}] Installed
[${CQ_KEY^^}] Quit")
function go_pacman() {
cmd=$(pacman -Slq | fzf --prompt ' pacman> ' \
--header "${HEADER}" \
--bind "${CP_KEY}:execute:pacsync 'pacman'" \
--bind "${CA_KEY}:execute:pacsync 'aur'" \
--bind "${CI_KEY}:execute:pacsync 'installed'" \
--bind "${CQ_KEY}:execute:pkill fzf" \
--bind "${TP_KEY}:toggle-preview" \
--multi --height=80% --preview 'sleep 2; yay -Si {1}' \
--preview-window 'right,wrap') #| xargs -ro pacman -S
cmd=${cmd//$'\n'/ } # newline -> space
if [ -n "$cmd" ]; then
pikaur -S "$cmd"
fi
exit
2022-09-05 12:16:33 -04:00
}
2022-10-30 08:48:36 -04:00
function go_aur() {
cmd=$(yay -Slq | fzf --prompt ' pikaur> ' \
--header "${HEADER}" \
--bind "${CP_KEY}:execute:pacsync 'pacman'" \
--bind "${CA_KEY}:execute:pacsync 'aur'" \
--bind "${CI_KEY}:execute:pacsync 'installed'" \
--bind "${CQ_KEY}:execute:pkill fzf" \
--bind "${TP_KEY}:toggle-preview" \
--multi --height=80% --preview 'sleep 2; yay -Si {1}' \
--preview-window 'right,wrap') #| xargs -ro pikaur -S
cmd=${cmd//$'\n'/ } # newline -> space
if [ -n "$cmd" ]; then
pikaur -R "$cmd"
fi
exit
2022-10-25 02:07:52 -04:00
}
2022-09-05 12:16:33 -04:00
function go_installed() {
2022-10-30 08:48:36 -04:00
cmd=$(pacman -Qq | fzf --prompt ' installed> ' \
--header "${HEADER}" \
--bind "${CP_KEY}:execute:pacsync 'pacman'" \
--bind "${CA_KEY}:execute:pacsync 'aur'" \
--bind "${CI_KEY}:execute:pacsync 'installed'" \
--bind "${CQ_KEY}:execute:pkill fzf" \
--bind "${TP_KEY}:toggle-preview" \
--multi --height=80% --preview 'sleep 2; yay -Si {1}' \
--preview-window 'right,wrap') #| xargs -ro pacman -S
cmd=${cmd//$'\n'/ } # newline -> space
if [ -n "$cmd" ]; then
pikaur -R "$cmd"
fi
exit
2022-09-05 12:16:33 -04:00
}
2022-10-30 08:48:36 -04:00
if command -v fzf > /dev/null 2>&1; then
FUZZYSEL=fzf
fuzzy_default_options=(
"--inline-info" "--cycle" "--ansi" "-e"
"--no-sort" "--layout=reverse-list"
"--border=${BORDER:-sharp}"
)
export FZF_DEFAULT_OPTS="${fuzzy_default_options[*]}"
else
echo "Unable to find 'fzf' fuzzy finder"
exit
fi
2022-09-05 12:16:33 -04:00
case $1 in
*pacman)
2022-10-30 08:48:36 -04:00
go_pacman
;;
*aur)
go_aur
;;
2022-09-05 12:16:33 -04:00
*installed)
2022-10-30 08:48:36 -04:00
go_installed
;;
2022-09-05 12:16:33 -04:00
*)
2022-10-30 08:48:36 -04:00
go_pacman
;;
esac