Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. # bash completion function for hdf 'h5ls'
  2. _h5ls()
  3. {
  4. local cur prev opts WORDS end
  5. COMPREPLY=()
  6. cur="${COMP_WORDS[COMP_CWORD]}"
  7. prev="${COMP_WORDS[COMP_CWORD-1]}"
  8. opts="-h --help -d --data -r --recursive -S --simple"
  9.  
  10. local TAIL_WD=$(( ${#COMP_WORDS[@]} - ${COMP_CWORD} - 1 ))
  11. if [[ $TAIL_WD > 0 ]]
  12. then
  13. local DO_OPTS=1
  14. elif [[ ${cur} == -* && $TAIL_WD == 0 ]]
  15. then
  16. local DO_OPTS=1
  17. fi
  18.  
  19.  
  20. if [[ ${DO_OPTS} ]]
  21. then
  22. COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  23. return 0
  24. elif [[ $cur == *.h5/* ]] ; then
  25. WORDS=""
  26. local cmd="h5ls ${cur%/*}/"
  27. for end in $(eval $cmd | awk '$2 == "Group" {print $1}' )
  28. do
  29. WORDS+=${cur%/*}/${end}/" "
  30. done
  31. for end in $(eval $cmd | awk '$2 == "Dataset" {print $1}' )
  32. do
  33. WORDS+=${cur%/*}/${end}" "
  34. done
  35.  
  36. cmd="compgen -W \"${WORDS}\" -- $cur"
  37. COMPREPLY=( $(eval $cmd) )
  38. return 0
  39. else
  40. COMPREPLY=( $(compgen -o plusdirs -f -X "!*.h5*" -- ${cur}) )
  41. return 0
  42. fi
  43. }
  44. complete -o filenames -o nospace -F _h5ls h5ls
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement