aboutsummaryrefslogtreecommitdiff
path: root/functions/syncscript.fish
blob: 7b838f8a1cad9c0682e348a1867eea72b3e48e25 (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
30
31
32
33
34
35
36
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")

  # Skip scripts not present in target tree
  if not test -e $basescript
    continue
  end

  # Skip scripts tracked by git
  if git -C (path dirname $script) ls-files --error-unmatch $script &>/dev/null
    continue
  end

  # Skip identical scripts
  if cmp -s $basescript $script
    continue
  end

  if ask "Copy $basescript to $targetdir?"
    cp -f --preserve="timestamps,mode" $basescript $script
  end

end

end