mirror of
https://github.com/The-Repo-Club/DotFiles.git
synced 2024-11-25 00:38:20 -05:00
120 lines
3.0 KiB
Bash
Executable File
120 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#-*-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:
|
|
# Wed 16 November 2022, 06:44:01 AM [GMT]
|
|
#
|
|
#Description:
|
|
# FZF menu for pacman yay or pikaur
|
|
#
|
|
#Dependencies:
|
|
# bash, pacman, yay, pikaur
|
|
#
|
|
# shellcheck disable=all
|
|
|
|
colorize() {
|
|
local string
|
|
string="${1//\[/\\033\[0;32m\[}"
|
|
string="${string//\]/\]\\033\[0m}"
|
|
echo -n -e "${string}"
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
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 -S "$cmd"
|
|
fi
|
|
exit
|
|
}
|
|
|
|
function go_installed() {
|
|
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
|
|
}
|
|
|
|
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
|
|
|
|
case $1 in
|
|
*pacman)
|
|
go_pacman
|
|
;;
|
|
*aur)
|
|
go_aur
|
|
;;
|
|
*installed)
|
|
go_installed
|
|
;;
|
|
*)
|
|
go_pacman
|
|
;;
|
|
esac
|