v-search-command 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. # info: search for available commands
  3. # options: ARG1 [ARG...]
  4. # labels: hestia
  5. #
  6. # example: v-search-command web
  7. #
  8. # This function searches for available Hestia Control Panel commands
  9. # and returns results based on the specified criteria.
  10. # Originally developed for VestaCP by Federico Krum
  11. # https://github.com/FastDigitalOceanDroplets/VestaCP/blob/master/files/v-search-command
  12. #----------------------------------------------------------#
  13. # Variable&Function #
  14. #----------------------------------------------------------#
  15. source $HESTIA/func/main.sh
  16. #----------------------------------------------------------#
  17. # Verifications #
  18. #----------------------------------------------------------#
  19. if [ $# -eq 0 ]; then
  20. echo "ERROR: No search arguments specified."
  21. echo "Usage: v-search-command ARG1 [ARG2] [ARG...]"
  22. exit 1
  23. fi
  24. #----------------------------------------------------------#
  25. # Action #
  26. #----------------------------------------------------------#
  27. SearchPath=`ls -a $HESTIA/bin/ | sort`
  28. TotalItems=`ls -a $HESTIA/bin/ | sort | wc -l`
  29. for i; do
  30. SearchResults=`echo $SearchPath | tr " " "\n" | grep $i`
  31. FoundItems=`echo $SearchResults | tr " " "\n" | grep $i | wc -l`
  32. done
  33. if [ -z "$SearchResults" ]; then
  34. echo "No available commands were found matching the specified criteria."
  35. echo "There are a total of $TotalItems commands available."
  36. else
  37. echo "Command Search Results"
  38. echo "================================="
  39. echo $SearchResults | tr " " "\n"
  40. echo "================================="
  41. echo "Found $FoundItems matching items in $TotalItems commands."
  42. fi
  43. exit