Advertisement
plirof2

bash file list selection

May 3rd, 2023 (edited)
1,140
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.99 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################
  3. ## GFX version OK
  4. #!/bin/bash
  5. LISTPATH="/opt/lampp/htdocs/tinymce_class/lessons/"
  6. prompt="Please select a file:"
  7. #options=( $(find -maxdepth 1 -print0 | xargs -0) )
  8. options=( $(find $LISTPATH -maxdepth 1 -print0 | xargs -0) )
  9. menu_list='';
  10. PS3="$prompt "
  11. count=0
  12.  
  13. echo "OPTIONS = "${options[@]}
  14.  
  15. for FILE in ${options[@]};
  16.     do
  17.         #menu_list="${menu_list} \"$count\" \"$FILE\" \"off\" "
  18.         #menu_list="${menu_list} \"$FILE\" \"---\" \"off\" "
  19.         menu_list="${menu_list} $FILE \"$count\" \"off\" "
  20.         let "count=count+1"
  21.         #echo $count
  22.     done
  23.  
  24. #echo "MENULIST= "$menu_list
  25.  
  26.  
  27. #choice=$(Xdialog --stdout --left --wrap --no-cancel --title "MY OPTIONS" --menu "Please select" 60 100 50 "${options[@]}" )
  28. ##shows only one###choice=$(Xdialog --stdout --left --wrap --no-cancel --title "MY OPTIONS" --checklist "Please select" 60 100 50 ${menu_list[@]} )
  29. choice=$(Xdialog --stdout --left --wrap --no-cancel --title "MY OPTIONS" --checklist "Please select" 60 100 50 ${menu_list[@]} )
  30.                
  31. echo "YOUR CHOICE : "$choice
  32. leafpad $choice
  33. #ls -ld "$choice"
  34.  
  35. ######################################################
  36. ## No GFX version ok working  https://stackoverflow.com/questions/15807845/list-files-and-show-them-in-a-menu-with-bash
  37. LISTPATH="/opt/lampp/htdocs/tinymce_class/lessons/"
  38. prompt="Please select a file:"
  39. #options=( $(find -maxdepth 1 -print0 | xargs -0) )
  40. options=( $(find $LISTPATH -maxdepth 1 -print0 | xargs -0) )
  41.  
  42. PS3="$prompt "
  43. select opt in "${options[@]}" "Quit" ; do
  44.     if (( REPLY == 1 + ${#options[@]} )) ; then
  45.         exit
  46.  
  47.     elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
  48.         echo  "You picked $opt which is file $REPLY"
  49.         break
  50.  
  51.     else
  52.         echo "Invalid option. Try another one."
  53.     fi
  54. done    
  55.  
  56. leafpad "$opt"
  57. ls -ld "$opt"
  58.  
  59. #########################################################
  60. ## GFX version Simple A working
  61. #!/bin/bash
  62. ###https://www.baeldung.com/linux/shell-script-simple-select-menu
  63. LISTPATH="/opt/lampp/htdocs/tinymce_class/lessons/"
  64. prompt="Please select a file:"
  65. #options=( $(find -maxdepth 1 -print0 | xargs -0) )
  66. options=( $(find $LISTPATH -maxdepth 1 -print0 | xargs -0) )
  67. menu_list='';
  68. PS3="$prompt "
  69.  
  70.  
  71.  
  72. echo $options
  73.  
  74. #ANSWER=$(Xdialog --stdout --left --wrap --icon /usr/local/lib/X11/pixmaps/nicOS.png --no-cancel --title "nicOS-Utility-Suite" --checklist "Select ." 60 100 50 ${options})
  75.  
  76.  
  77. choice=$(Xdialog --stdout --left --wrap --no-cancel --title "MY OPTIONS" \
  78.                  --menu "Please select" 60 100 50 "${options[@]}" \
  79.                  #
  80.                  #2>&1 >/dev/tty)
  81.                  )
  82. #ANSWER=$(Xdialog --stdout --left --wrap --icon /usr/local/lib/X11/pixmaps/nicOS.png --no-cancel --title "nicOS-Utility-Suite" --checklist "Select ." 60 100 50 ${menu_list})
  83.  
  84.  
  85. echo "YOUR CHOICE : "$choice
  86. leafpad "$choice"
  87. ls -ld "$choice"
  88.  
  89.  
  90. ####################################################
  91. ### GFX version (better )
  92.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement