Advertisement
Guest User

Untitled

a guest
Oct 6th, 2008
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.01 KB | None | 0 0
  1. #! /bin/sh
  2.  
  3. # If MAX_ARG_PAGES is 32 and page size is 4KB, then there is only 128kB for environment variables and arguments.
  4. # Since dynamic menu items are passed in via command line, only return about 100kB of data or less.
  5. # Any more, and there will be an error when launching the menu.
  6. FILEMENU_MAXNUMBEROFFILES=60
  7. FILEMENU_MAXAGEINDAYS=180
  8.  
  9.  
  10. function listFiles() {
  11. DirPath=$1
  12. ModifyTime=$2
  13.  
  14.   find "$DirPath" -maxdepth 1 -mindepth 1 -type f -mtime "$ModifyTime" -print
  15. }
  16.  
  17. function listFilesForMenuXarg() {
  18. DirPath=$1
  19. ModifyTime=$2
  20.  
  21.   listFiles "$DirPath" "$ModifyTime" | tail -n $FILEMENU_MAXNUMBEROFFILES | while read filePath; do
  22.     echo -e -n "$(basename "$filePath")\0000$(date -r /opt "+%Y-%m-%d") $(cat "$filePath" | wc -c)\0000"
  23.   done
  24. }
  25.  
  26. function fileMenuXarg() {
  27. DirPath=$1
  28.  
  29.   while [ true ]; do
  30.     exec 3>&1
  31.     exec 4>&1
  32.     fileName=$(listFilesForMenuXarg "$DirPath" "-$FILEMENU_MAXAGEINDAYS" 0>&4 | xargs -0 dialog --input-fd 4 --default-item "$fileName" --menu "Xarg Test - Select a file." 0 0 0 2>&1 1>&3)
  33.     returnCode=$?
  34.     exec 3>&-
  35.     exec 4>&-
  36.  
  37.     if [ $returnCode -ne 0 ]; then
  38.       return
  39.     fi
  40.  
  41.     cat "$DirPath/$fileName" | less
  42.   done
  43. }
  44.  
  45. function listFilesForMenuSet() {
  46. DirPath=$1
  47. ModifyTime=$2
  48.  
  49.   listFiles "$DirPath" "$ModifyTime" | tail -n $FILEMENU_MAXNUMBEROFFILES | while read filePath; do
  50.     echo "$(basename "$filePath")"
  51.     echo "$(date -r /opt "+%Y-%m-%d") $(cat "$filePath" | wc -c)"
  52.   done
  53. }
  54.  
  55. function fileMenuSet() {
  56. DirPath=$1
  57.  
  58.   while [ true ]; do
  59.     IFS=$'\n'
  60.     set $(listFilesForMenuSet "$DirPath" "-$FILEMENU_MAXAGEINDAYS")
  61.     IFS=$' \t\n'
  62.  
  63.     exec 3>&1
  64.     fileName=$(dialog --default-item "$fileName" --menu "Set Test - Select a file." 0 0 0 "$@" 2>&1 1>&3)
  65.     exec 3>&-
  66.     returnCode=$?
  67.     if [ $returnCode -ne 0 ]; then
  68.       return
  69.     fi
  70.  
  71.     cat "$DirPath/$fileName" | less
  72.  
  73.   done
  74. }
  75.  
  76. # You must have some files in your home directory for this example to work.
  77. fileMenuSet "$HOME"
  78. fileMenuXarg "$HOME"
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement