This commit is contained in:
@ -8,11 +8,48 @@
|
||||
# for each git repo print the name of the repo, the datestamp of the last commit,
|
||||
# the nubmer of changes since then, and whether it's clean or not.
|
||||
|
||||
# if no argument is provided, use the current directory
|
||||
DIR="${1:-.}"
|
||||
# Configuration file path
|
||||
CONFIG_FILE="$HOME/.config/whatsdirty.conf"
|
||||
|
||||
# make directory canonical
|
||||
DIR=$(cd "$DIR" 2>/dev/null && pwd) || { echo "Error: Directory '$1' not found"; exit 1; }
|
||||
# Function to save directory to config
|
||||
save_directory() {
|
||||
local dir="$1"
|
||||
mkdir -p "$(dirname "$CONFIG_FILE")"
|
||||
echo "$dir" > "$CONFIG_FILE"
|
||||
}
|
||||
|
||||
# Function to load directory from config
|
||||
load_directory() {
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
cat "$CONFIG_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
# Determine which directory to use
|
||||
if [ $# -eq 0 ]; then
|
||||
# No argument provided - try to load from config
|
||||
SAVED_DIR=$(load_directory)
|
||||
if [ -z "$SAVED_DIR" ]; then
|
||||
echo "Error: No directory specified and no saved directory found."
|
||||
echo "Usage: $0 <directory>"
|
||||
echo "The specified directory will be saved for future use."
|
||||
exit 1
|
||||
fi
|
||||
DIR="$SAVED_DIR"
|
||||
else
|
||||
# Argument provided - use it and save to config
|
||||
DIR="$1"
|
||||
# Validate and canonicalize the directory first
|
||||
DIR=$(cd "$DIR" 2>/dev/null && pwd) || { echo "Error: Directory '$1' not found"; exit 1; }
|
||||
save_directory "$DIR"
|
||||
fi
|
||||
|
||||
# Make sure directory is canonical (in case loaded from config)
|
||||
DIR=$(cd "$DIR" 2>/dev/null && pwd) || {
|
||||
echo "Error: Saved directory '$DIR' no longer exists";
|
||||
rm -f "$CONFIG_FILE"
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# Color codes
|
||||
RED='\033[0;31m'
|
||||
|
Reference in New Issue
Block a user