diff --git a/whatsdirty/dropshell-tool-config.json b/whatsdirty/dropshell-tool-config.json new file mode 100644 index 0000000..09cfc0d --- /dev/null +++ b/whatsdirty/dropshell-tool-config.json @@ -0,0 +1,6 @@ +{ + "aliases": [ + "whatsdirty" + ], + "setup_script": "setup_script.sh" +} \ No newline at end of file diff --git a/whatsdirty/install.sh b/whatsdirty/install.sh new file mode 100644 index 0000000..89098db --- /dev/null +++ b/whatsdirty/install.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -euo pipefail + +#SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +echo "Installing whatsdirty" + +if ! command -v dropshell-tool ; then + + ARCH=$(uname -m) + wget "https://getbin.xyz/dropshell-tool:latest-${ARCH}" -O bootstrap && chmod a+x bootstrap + ./bootstrap install dropshell-tool + rm ./bootstrap + VERSION=$(dropshell-tool version) + echo "Dropshell tool $VERSION installed" + +fi + +dropshell-tool install whatsdirty diff --git a/whatsdirty/publish.sh b/whatsdirty/publish.sh new file mode 100644 index 0000000..d03221e --- /dev/null +++ b/whatsdirty/publish.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +# run sos to upload +"${SCRIPT_DIR}/../sos/sos" upload "getbin.xyz" "${SCRIPT_DIR}/whatsdirty.sh" "whatsdirty:latest" +"${SCRIPT_DIR}/../sos/sos" upload "getbin.xyz" "${SCRIPT_DIR}/install.sh" "whatsdirty-install:latest" + +# publish the tool + +mkdir -p ${SCRIPT_DIR}/tool +cp ${SCRIPT_DIR}/whatsdirty.sh ${SCRIPT_DIR}/tool + + + diff --git a/whatsdirty/setup_script.sh b/whatsdirty/setup_script.sh new file mode 100755 index 0000000..6b8822c --- /dev/null +++ b/whatsdirty/setup_script.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo "whatsdirty tool setup completed successfully!" +echo "Use 'whatsdirty ' to scan git repositories for uncommitted changes." +echo "The specified directory will be saved for future use." diff --git a/whatsdirty/whatsdirty.sh b/whatsdirty/whatsdirty.sh index f2e8f94..d087646 100755 --- a/whatsdirty/whatsdirty.sh +++ b/whatsdirty/whatsdirty.sh @@ -227,5 +227,74 @@ main() { print_clean_repositories "$TEMP_FILE" } +# === Autocomplete Function === + +handle_autocomplete() { + local cur_word="${COMP_WORDS[COMP_CWORD]}" + local prev_word="${COMP_WORDS[COMP_CWORD-1]}" + + # If we're completing the first argument after 'whatsdirty' + if [ ${COMP_CWORD} -eq 1 ]; then + # Suggest common directories and saved directory + local saved_dir=$(load_directory) + local suggestions="" + + # Add saved directory if it exists + if [ -n "$saved_dir" ] && [ -d "$saved_dir" ]; then + suggestions="$saved_dir" + fi + + # Add common development directories + for dir in ~/code ~/projects ~/dev ~/src ~/workspace /home/*/code /home/*/projects; do + if [ -d "$dir" ]; then + # Only add if it contains git repositories + if find "$dir" -maxdepth 2 -name ".git" -type d 2>/dev/null | head -1 | grep -q .; then + suggestions="$suggestions $dir" + fi + fi + done + + # Directory completion for current word + if [ -n "$cur_word" ]; then + # Use compgen for directory completion + local dir_completions=($(compgen -d -- "$cur_word")) + # Add our suggestions that match the current word + local matching_suggestions=($(echo "$suggestions" | tr ' ' '\n' | grep "^$cur_word" | sort -u)) + # Combine and deduplicate + COMPREPLY=($(printf '%s\n' "${dir_completions[@]}" "${matching_suggestions[@]}" | sort -u)) + else + # No current word, suggest all our directories plus general directory completion + local dir_completions=($(compgen -d)) + local all_suggestions=($(echo "$suggestions" | tr ' ' '\n' | sort -u)) + # Combine and deduplicate, but limit to reasonable number + COMPREPLY=($(printf '%s\n' "${all_suggestions[@]}" "${dir_completions[@]}" | sort -u | head -20)) + fi + fi +} + +# Check if we're being called for autocomplete +if [ "$1" = "autocomplete" ]; then + # This is called when the tool is being used for bash completion + # The arguments after 'autocomplete' are the completion context + shift + + # Set up COMP_WORDS and COMP_CWORD from arguments + COMP_WORDS=("$@") + COMP_CWORD=$(($# - 1)) + + # Generate completions + handle_autocomplete + + # Print completions, one per line + printf '%s\n' "${COMPREPLY[@]}" + exit 0 +fi + +# Check if we're being called to show version +if [ "$1" = "version" ]; then + echo "whatsdirty 1.0.0" + exit 0 +fi + # Execute main function with all arguments main "$@" \ No newline at end of file