aboutsummaryrefslogtreecommitdiff
path: root/functions/syncscript.fish
blob: e1511cf87e61fc7a763b14cb1ab5500493500c33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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