2

I've developed a lot of useful scripts and aliases at work over the past few years, and it has slowly evolved into a toolchain used by many people across several organizations.

I've done my best to document this, but things are moving so fast that I'm constantly adding new helpers in various places.

There are about a dozen different bash files that developers can source in their *rc depending on which helpers they want.

Some files contain a bunch of small aliases like so:

alias a1="";
alias a2="";
alias a3="";
alias a4="";

Some files contain more advanced helpers like so:

function complex_helper {
  ENV1=()
  ENV2=0
  while :; do
      case $1 in
          -h|-\?|--help)
            show_help
            HELP=1
            break # Not calling exit here because it's a function and we want to keep the current shell open
            ;;
          -i|--id)
              ENV1+=("$2")
              shift
              ;;
          -t|--test)
              ENV2=1
              ;;
          --) # End of all options.
              shift
              break
              ;;
          -?*)
              printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
              ;;
          *) # Default case: No more options, so break out of the loop.
              break
      esac

      shift
  done

  # Some logic here
}

Ideally, I'd like to achieve the following:

  • Have a unified cli command to encapsulate everything
  • Be able to type in --help and see all the commands available. For example, if I added alias a5, it would show up as well
  • Have tab complete
  • Make it easy for others to add their own helpers along with a quick "help" command

In the past, I started making a python binary that would use the argparser + tab complete, and use the os module to execute bash commands, and I'm open to revisiting this approach. I'm also willing to do any refactoring that is necessary as long as it ends in a maintainable longterm approach.

I'm really looking forward to any interesting suggestions or ideas the community will have!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.