From d898f86d814ba9ea06e37bd06f76e9961ac41fba Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 29 Aug 2020 02:58:09 +0000 Subject: [PATCH] flesh out some more fzf features --- extensions/fzf.ksh | 41 +++++++++++++++++++++++++++++++++++++++-- ohmy.ksh | 2 ++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/extensions/fzf.ksh b/extensions/fzf.ksh index fdc152f..21b9d3d 100755 --- a/extensions/fzf.ksh +++ b/extensions/fzf.ksh @@ -1,3 +1,40 @@ -h() { - fc -ln | fzf | ksh +zh() { + fc -ln | eval `fzf` +} + +zpkg() { + local _pkg _usage + + _usage="zpkg add|rm" + + if [ ! -f /usr/local/share/sqlports ]; then + echo "please install sqlports" + return 1 + fi + + if [ ! -e /usr/local/bin/sqlite3 ]; then + echo "please install sqlite3" + return 1 + fi + + if [ -z $1 ]; then + echo $_usage + return 1 + else + case $1 in + add) + _pkg=$(/usr/local/bin/sqlite3 -separator " " \ + /usr/local/share/sqlports \ + "select distinct fullpkgname from Ports;" |\ + fzf --preview "/usr/sbin/pkg_info {1}") + [ ! -z $_pkg ] && ${OHMY_DO} /usr/sbin/pkg_add $_pkg + ;; + rm) + _pkg=$(ls -1 /var/db/pkg | fzf --preview "/usr/sbin/pkg_info {1}") + [ ! -z $_pkg ] && ${OHMY_DO} /usr/sbin/pkg_delete $_pkg + ;; + *) + echo $_usage + esac + fi } diff --git a/ohmy.ksh b/ohmy.ksh index 8604954..0f88567 100755 --- a/ohmy.ksh +++ b/ohmy.ksh @@ -2,6 +2,8 @@ #${DEBUG} +OHMY_DO=${OHMY_DO:-doas} + # Stub our load functions paths() { return 0