aboutsummaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
authorDeposite Pirate2026-02-18 05:53:37 +0100
committerDeposite Pirate2026-02-18 05:53:37 +0100
commite5fac87405c6a01acc3630b0f17e7e10df858274 (patch)
treebd3e0336afe8f2c5306669aa981bf9cbd5b7441d /functions
parent164bb33a6464f3c7f21e82ccd9d70f8f52acd6af (diff)
New script to synchronise scripts
This new script synchronises the fish scripts in two trees skipping the scripts not present in the target tree or those tracked by git in the target tree. new file: functions/syncscript.fish
Diffstat (limited to 'functions')
-rw-r--r--functions/syncscript.fish29
1 files changed, 29 insertions, 0 deletions
diff --git a/functions/syncscript.fish b/functions/syncscript.fish
new file mode 100644
index 0000000..e1511cf
--- /dev/null
+++ b/functions/syncscript.fish
@@ -0,0 +1,29 @@
+function syncscript --description "Synchronise fish script between two \
+ directories trees" -a basedir -a targetdir
+
+if test (count $argv) -lt 2
+ echo "Missing arguments."
+ return 1
+end
+
+set -f fishscriptdirs '/.config/fish/'
+
+for script in (find $targetdir -type f -path "*$fishscriptdirs*/*" -name "*.fish")
+
+ set -l basescript (string replace "$targetdir" "$basedir" "$script")
+
+ if not test -e $basescript
+ continue
+ end
+
+ if git -C (path dirname $script) ls-files --error-unmatch $script &>/dev/null
+ continue
+ end
+
+ if ask "Copy $basescript to $targetdir?"
+ cp -f --preserve="timestamps,mode" $basescript $script
+ end
+
+end
+
+end