Skip to content

Instantly share code, notes, and snippets.

@vndmp4
Created November 9, 2022 12:55
Show Gist options
  • Save vndmp4/ea711ec7522abc15c964dcc7c482f21e to your computer and use it in GitHub Desktop.
Save vndmp4/ea711ec7522abc15c964dcc7c482f21e to your computer and use it in GitHub Desktop.
dnf + fzf
fzf_dnf_install() {
local package
package=$1
dnf_fzf() {
local cache=$HOME/.cache/dnf_list.txt
if test -f "$cache"; then
package=$(\cat $cache | fzf_down)
else
dnf list | awk '{print $1}' | tail -n +4 >$cache
package=$(\cat $cache | fzf_down)
fi
if [[ -n $package ]]; then
sudo dnf install -y $package
fi
}
if [[ -n $package ]]; then
sudo dnf install -y $package
ERROR=$?
if [[ ERROR -eq 1 ]]; then
dnf_fzf
fi
else
dnf_fzf
fi
}
alias ins='fzf_dnf_install'
dnf_fzf_remove() {
local package
package=$1
dnf_fzf() {
# cron job daily to update cache
local cache=$HOME/.cache/dnf_list_installed.txt
if test -f "$cache"; then
package=$(\cat $cache | fzf_down)
else
dnf list --installed | awk '{print $1}' | tail -n +4 >$cache
package=$(\cat $cache | fzf_down)
fi
if [[ -n $package ]]; then
sudo dnf remove -y $package
fi
}
if [[ -n $package ]]; then
# TODO: don't use `rg` echo check issue for some case `rg` is not available by default -> use command system had default
sudo dnf remove -y $package | rg "no match" &>/dev/null
ERROR=$?
if [[ ERROR -eq 0 ]]; then
dnf_fzf
else
echo "removed $package"
fi
else
dnf_fzf
fi
}
alias uins='dnf_fzf_remove'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment