Skip to content

Commit

Permalink
Format generate-shell-completions.sh with Shfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
bergercookie committed Jan 21, 2024
1 parent c2395f3 commit a0f5eaf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
65 changes: 33 additions & 32 deletions scripts/generate-shell-completions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,70 @@ set -e

# helpers ----------------------------------------------------------------------
function finish {
tabs 8
tabs 8
}
trap finish EXIT

function inside_virtualenv() {
python3 -qc "import sys; sys.exit(0 if sys.prefix != sys.base_prefix else 1)"
python3 -qc "import sys; sys.exit(0 if sys.prefix != sys.base_prefix else 1)"
}

function inside_git_repo() {
git rev-parse
git rev-parse
}

function completion_dir_for() {
dir_=$completions_dir/$1
mkdir -p $dir_
echo "$dir_/$2"
dir_=$completions_dir/$1
mkdir -p $dir_
echo "$dir_/$2"
}

function get_ext_for() {
if [[ "$1" == "bash" || "$1" == "zsh" ]]; then
echo ".sh"
elif [[ "$1" == "fish" ]]; then
echo ".fish"
else
echo ""
fi
if [[ $1 == "bash" || $1 == "zsh" ]]; then
echo ".sh"
elif [[ $1 == "fish" ]]; then
echo ".fish"
else
echo ""
fi
}

# sanity checks ----------------------------------------------------------------
if ! inside_virtualenv; then
echo "You are not inside a virtualenv, can't proceed. Run "poetry shell" first".
exit 1
echo "You are not inside a virtualenv, can't proceed. Run "poetry shell" first".
exit 1
fi

if ! inside_git_repo; then
echo "You are not inside a git repo..."
exit 1
echo "You are not inside a git repo..."
exit 1
fi

git_root_dir=$(git rev-parse --show-toplevel)
this_file="$git_root_dir/scripts/generate-shell-completions.sh"

if [[ $(basename $git_root_dir) != "syncall" ]]; then
echo "This isn't the syncall repo -> $git_root_dir"
exit 1
if ! test -f "$this_file"; then
echo "This doesn't seem to be the syncall repo -> $git_root_dir"
exit 1
fi

completions_dir="${git_root_dir}/completions"
mkdir -p $completions_dir

# main loop --------------------------------------------------------------------
for exec in tw_gkeep_sync tw_notion_sync tw_gcal_sync tw_asana_sync tw_caldav_sync fs_gkeep_sync tw_gtasks_sync; do
tabs 4
# Run the following, grab the output and dumpt it to the completions/ files...
# _TW_GKEEP_SYNC_COMPLETE=fish_source tw_gkeep_sync
envvar="_$(echo $exec | tr "[:lower:]" "[:upper:]")_COMPLETE"
for shell in "bash" "zsh" "fish"; do
echo -e "Generating completions for [$exec\t| $shell\t]"
tabs 4
# Run the following, grab the output and dumpt it to the completions/ files...
# _TW_GKEEP_SYNC_COMPLETE=fish_source tw_gkeep_sync
envvar="_$(echo $exec | tr "[:lower:]" "[:upper:]")_COMPLETE"
for shell in "bash" "zsh" "fish"; do
echo -e "Generating completions for [$exec\t| $shell\t]"

# Execute command, grab its output, redirect it to file.
export $envvar=${shell}_source
contents=$($exec)
# Execute command, grab its output, redirect it to file.
export $envvar=${shell}_source
contents=$($exec)

path="$(completion_dir_for $shell $exec)$(get_ext_for $shell)"
echo "$contents" > "$path"
done
path="$(completion_dir_for $shell $exec)$(get_ext_for $shell)"
echo "$contents" > "$path"
done
done
1 change: 0 additions & 1 deletion syncall/scripts/tw_notion_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def main(
verbose: int,
combination_name: str,
custom_combination_savename: str,
do_list_combinations: bool,
list_resolution_strategies: bool,
pdb_on_error: bool,
):
Expand Down

0 comments on commit a0f5eaf

Please sign in to comment.