diff --git a/.DOTFISHED b/.DOTFISHED new file mode 100644 index 0000000..e69de29 diff --git a/functions/confirm.fish b/functions/confirm.fish new file mode 100644 index 0000000..ee0a906 --- /dev/null +++ b/functions/confirm.fish @@ -0,0 +1,13 @@ +function confirm + set -g ANSWER (read -n 1 -P "Confirm? (y/N) ") + + if test -z $ANSWER + return 1 + else if test $ANSWER = "y" + return 0 + else if test $ANSWER = "Y" + return 0 + else + return 1 + end +end \ No newline at end of file diff --git a/functions/dotfish.fish b/functions/dotfish.fish index 7ec912c..2bea88c 100644 --- a/functions/dotfish.fish +++ b/functions/dotfish.fish @@ -9,8 +9,8 @@ function dotfish echo_highlight "$TARGET" \n if test -z $TARGET - echo_progress "Invalid target, exiting with 1" - exit 1 + echo_progress "Couldn't detect target, exiting..." \n + return 1 end set -g FISHCONFIG ~(echo $TARGET)/.config/fish @@ -18,16 +18,28 @@ function dotfish echo_progress "Destination directory is: " echo_highlight "$FISHCONFIG" \n + if not test -e "$FISHCONFIG/.DOTFISHED" + echo_progress "Conflicting config detected, confirm deletion?" \n + if confirm + echo_progress "Deleting old config..." \n + rm -rf $FISHCONFIG + else + echo_progress "Deletion was refused, exiting..." \n + return 2 + end + end + + if test -d $FISHCONFIG - echo_progress "Pulling from Git..." \n + echo_progress "Existing config detected, pulling from Git..." \n git -C $FISHCONFIG pull else - echo_progress "Cloning from Git..." \n + echo_progress "No config detected, cloning from Git..." \n git clone "https://github.com/Steffo99/.config-fish" $FISHCONFIG end echo_progress "Fixing permissions..." \n chown -R "$TARGET:" $FISHCONFIG - echo_progress "Update complete!" + echo_progress "Update complete!" \n end \ No newline at end of file