Advertisement
pintcat

WIP approach of a text based file browser

Mar 12th, 2025 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.49 KB | Software | 0 0
  1. #!/bin/sh
  2.  
  3. FBR_DIFS=$IFS
  4. [ -n "$1" ] && DEF_PATH=${1%/}/ || DEF_PATH="$PWD"/
  5. FBR_PATH=$DEF_PATH
  6. [ $((FBR_X=$(stty size | cut -d" " -f2)-3)) -gt 200 ] && FBR_X=200
  7. FBR_Y=$(($(stty size | cut -d" " -f1)-3))
  8. FBR_FG=white
  9. FBR_BG=gray
  10. export NEWT_COLORS="window=,$FBR_BG;title=$FBR_FG,$FBR_BG;border=,$FBR_BG;textbox=,$FBR_BG;button=,black;listbox=,$FBR_BG;actlistbox=$FBR_FG,$FBR_BG"
  11.  
  12. FBR_GETLIST(){
  13.     FBR_DIR=$(ls -agGph --time-style=+ "$1" | grep '^d' | awk -F' ' '{printf $1" "$2" (D)";$1=$2=$3="";print $0}' | tail -n +2 | sed 's/.$//')"\n"
  14.     FBR_DIR=$FBR_DIR$(ls -agGph --time-style=+ "$1" | grep '^-')
  15.     IFS="/"
  16.    
  17.     whiptail --title "Select file..." --menu "Current path: $1" $FBR_Y $FBR_X $(($FBR_Y-8)) \
  18.              $(printf "$FBR_DIR" | awk -F ' ' '{if (NF >=4) {i=4; while (i<NF) {printf $i" "; i++}; {printf $i"/" $3"/"}}}') \
  19.              3>&1 1>&2 2>&3 3>&-
  20.     #[ $? -gt 0 ] && echo /
  21.     IFS=$FBR_DIFS
  22. }
  23.  
  24. FBR_FILEBROWSER(){
  25.     FBR_SEL=$(FBR_GETLIST "$FBR_PATH")
  26.     while [ -n "$FBR_SEL" ] && [ -d "$FBR_PATH/$FBR_SEL" ]; do
  27.         if [ "$FBR_SEL" = .. ]; then
  28.             [ ! "$FBR_PATH" = / ] && FBR_PATH=${FBR_PATH%/*/}/
  29.         else
  30.             FBR_PATH="$FBR_PATH$FBR_SEL"/
  31.         fi
  32.         FBR_SEL=$(FBR_GETLIST "$FBR_PATH")
  33.     done
  34.     if [ -z "$FBR_SEL" ]; then
  35.         echo Abbruch!
  36.     else
  37.         echo Path: $FBR_PATH/$FBR_SEL
  38.     fi
  39.     exit
  40.     IN=$IN_PATH$SEL
  41.     if [ -e "$IN" ]; then
  42.         if [ -d "$IN" ]; then
  43.             IN_PATH=$IN
  44.             FILEBROWSER
  45.         else
  46.             echo "AusgewΓ€hlte Datei: "$IN
  47.         fi
  48.     fi
  49. }
  50.  
  51. FBR_FILEBROWSER
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement