Skip to content

Latest commit

 

History

History
112 lines (93 loc) · 2.31 KB

File metadata and controls

112 lines (93 loc) · 2.31 KB

Actionfiles

config

[actionfiles]
    repo="https://github.com/gbraad-dotfiles/actionfiles"
    path="${HOME}/Projects/gbraad-dotfiles/actionfiles"

shared

actionfiles_list_names_and_descs() {
  local actionpath="$1"
  find -L "$actionpath" -type f -name '*.md' | sort | while IFS= read -r file; do
    relpath="${file#$actionpath/}"
    desc=$(grep -m1 '^# ' "$file" | sed 's/^# //')
    printf "%s\t%s\n" "$relpath" "$desc"
  done
}

actionfiles_pick() {
  local chosen_target
  local dir=$1
  chosen_target=$(printf "%s\n" "$(actionfiles_list_names_and_descs $dir)" | column -t -s $'\t' | fzf --prompt="Choose actionfile> ")
  chosen_target=$(echo "$chosen_target" | awk '{print $1}')
  echo ${dir}/${chosen_target}
}

exists

[ -d ${ACTIONFILES_PATH} ]

cd

cd ${ACTIONFILES_PATH}

checkout

git clone ${ACTIONFILES_REPO} ${ACTIONFILES_PATH}

update

cd ${ACTIONFILES_PATH}
git pull

default run alias

if ! app ${APPNAME} exists; then
  app ${APPNAME} checkout
fi
app ${APPNAME} aliases

aliases

alias dotfedora="run ${ACTIONFILES_PATH}/machine/dotfedora.md"

here-pick

actionfiles_pick $(pwd)

pick

actionfiles_pick ${ACTIONFILES_PATH}

aliases

Generate aliases for Actionfiles that use an alias section

Note

Needs to run in interactive-mode to allow the aliases to be exported

actions_aliases() {
  local actname actfile folder alias_name alias_cmd
  if [[ $(dotini apps --get "apps.aliases") == true ]]; then
    # Find all .md files in ACTIONFILES_PATH and subfolders
    find "${ACTIONFILES_PATH}" -type f -name '*.md' | while read -r mdfile; do

      actfile="${mdfile##*/}"
      actname="${actfile%.md}"

      folder="$(dirname "${mdfile}")"
      folder="${folder##*/}"

      if [[ "${folder}" == "$(basename "${ACTIONFILES_PATH}")" ]]; then
        alias_name="${actname}"
        alias_cmd="action ${ACTIONFILES_PATH}/${actfile}"
      else
        alias_name="${folder}-${actname}"
        alias_cmd="action ${ACTIONFILES_PATH}/${folder}/${actfile}"
      fi

      if grep -E -q '^###.*\balias\b' "$mdfile"; then
        alias "${alias_name}"="${alias_cmd}"
      fi
    done
  fi
}

actions_aliases
unset FILENAME
unset APPNAME
unset TITLE