Sha256: 77ce1d286deff8597bac1635282df604a5faa8d152fb6a9750cda6909cab3971

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

# lib/aia/aia_completion.bash
# Setup a prompt completion for use with
# the bash shell
#
# This script assumes that the system environment
# variable PROMPTS_DIR has been set correctly

_aia_completion() {
  # The current word being completed
  local cur_word="${COMP_WORDS[COMP_CWORD]}"

  # The previous word before the current word
  local prev_word="${COMP_WORDS[COMP_CWORD-1]}"

  # Store the previous directory to return to it later
  local initial_pwd=$(pwd)

  # Check if we are currently completing the option that requires prompt IDs
  if [[ "$prev_word" == "aia" ]]; then
    # Change directory to the prompts directory
    cd "$PROMPTS_DIR" || return

    # Generate a list of relative paths from the ~/.prompts directory (without .txt extension)
    local files=($(find . -name "*.txt" -type f | sed 's|^\./||' | sed 's/\.txt$//'))

    # Change back to the initial directory
    cd "$initial_pwd" || return

    # Generate possible matches and store them in the COMPREPLY array
    COMPREPLY=($(compgen -W "${files[*]}" -- "$cur_word"))
  else
    # If not the specific option, perform regular file completion
    COMPREPLY=($(compgen -o default -- "$cur_word"))
  fi
}

# Register the completion function for the aia command
complete -F _aia_completion aia

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
aia-0.5.0 lib/aia/aia_completion.bash
aia-0.4.4 lib/aia/aia_completion.bash
aia-0.4.3 lib/aia/aia_completion.bash
aia-0.4.2 lib/aia/aia_completion.bash
aia-0.4.1 lib/aia/aia_completion.bash
aia-0.3.20 lib/aia/aia_completion.bash
aia-0.3.19 lib/aia/aia_completion.bash
aia-0.3.4 lib/aia/aia_completion.bash
aia-0.3.3 lib/aia/aia_completion.bash