fdu

un du un peu interactif grâce à fzy - retour accueil

git clone git://bebou.netlib.re/fdu
Log | Files | Refs | README |

commit 8b95f7d72c2bf3dc6db70ccf8c32bbc9b7bd3e6c
parent debd96591d48e164b1771f87265810408f5d7492
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Fri, 15 Nov 2024 21:39:49 +0100

Gère le retour en arrière et les commandes ?

J'ai perdu le fil

Diffstat:
Mfdu.sh | 56+++++++++++++++++++++++++++++++++++---------------------
1 file changed, 35 insertions(+), 21 deletions(-)

diff --git a/fdu.sh b/fdu.sh @@ -5,7 +5,7 @@ VERSION="0.2" help() <<\% cat Un du un peu interactif pour un semblant de qdirstat (ou ncdu etc) -Usage : fdu [chemin] +Usage : fdu [-hv] [-c commande] [chemin] Le chemin par défaut est le repertoire courant @@ -28,26 +28,40 @@ analyser votre home tmpd=$(mktemp -d) trap "rm -rf $tmpd;exit 0" INT QUIT EXIT -case "${1}" -in ( -h | --help ) help ; exit -;; ( -v | --version ) echo "clidirstats $VERSION" ; exit -;; (*) - cur=$(cd "${1:-.}" && pwd) - while [ "$cur" != "quit" -a -d "$cur" ];do - tmpf=$(printf "%s" "$cur" | tr '/' '-') - if [ -f "$tmpd/$tmpf" ]; then - list=$(cat "$tmpd/$tmpf") - else - list=$(du -a -d 1 -h "$cur" | sort -hr | sed -E "s,$cur$,total,") - printf "%s" "$list" > $tmpd/$tmpf - fi - cur=$(printf "quit\nprev %s\n%s" "${cur%/*}" "$list" | fzy -l 20 | cut -f2) - done - - if [ ! -e "$cur" ];then - printf "%s" "Selected item not a file, exiting"; exit 1 +echo "a" | fzy -m -e "a" 2>&1 | grep "invalid option -- 'm'" \ + && multi="no" \ + || multi="yes" +echo "$multi" + +while getopts "hvc:" opt; do + case $opt in + ( c ) [ ! -z $OPTARG ] && eval "$opt='$OPTARG'" ;; + ( v ) printf "%s\n" "$VERSION"; exit ;; + ( h ) help; exit ;; + esac +done +shift $((OPTIND - 1)) + +cur=$(cd "${1:-.}" && pwd) +while [ "$cur" != "quit" ];do + tmpf=$(printf "%s" "$cur" | tr '/' '-') + + if [ -f "$tmpd/$tmpf" ]; then + list=$(cat "$tmpd/$tmpf") else - printf "%s is a file, what do you want to do ?\n" "$cur" + list=$(du -a -d 1 -h "$cur" | sort -hr | sed -E "s,.* $cur$,,") + printf "%s" "$list" > $tmpd/$tmpf fi -esac + [ "$multi" = "yes" ] \ + && cur=$(printf "quit\nprev %s\n%s" "${cur%/*}" "$list" | fzy -m -l 20 | cut -f2) \ + || cur=$(printf "quit\nprev %s\n%s" "${cur%/*}" "$list" | fzy -l 20 | cut -f2) + + + if [ -f "$cur" ];then + cmd=$(eval "echo $cur | xargs echo $cmd") + read -p "Execute \"$cmd\" ? (y/N) " a + [ "$a" = "y" ] && eval "$cmd" + cur=${cur%/*} + fi +done