You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.1 KiB
Fish
54 lines
1.1 KiB
Fish
5 years ago
|
#!/usr/bin/env fish
|
||
|
|
||
|
set DOTFILES_REPO (pwd)
|
||
|
|
||
|
## add thing to dotfiles repository (path or file)
|
||
|
function add_dotfiles
|
||
|
set system "$argv[1]"
|
||
|
set local "$argv[2]"
|
||
|
|
||
|
if grep -q -e "^$local" system_setup
|
||
|
echo "folder $local already in repo!"
|
||
|
return
|
||
|
end
|
||
|
|
||
|
if test -d "$system"
|
||
|
cp -r "$system" "$local"
|
||
|
rm -rf "$system"
|
||
|
else if test -f "$system"
|
||
|
cp "$system" "$local"
|
||
|
rm -f "$system"
|
||
|
else
|
||
|
echo "unknown file type at $argv[1]"
|
||
|
return
|
||
|
end
|
||
|
|
||
|
ln -s "$DOTFILES_REPO"/"$argv[2]" "$argv[1]"
|
||
|
|
||
|
echo "$argv[2] $argv[1]" >> system_setup
|
||
|
end
|
||
|
|
||
|
## link dotfiles everywhere
|
||
|
function restore_system
|
||
|
for line in (cat system_setup)
|
||
|
if test -z $line
|
||
|
continue
|
||
|
end
|
||
|
|
||
|
set line (string split -n " " "$line")
|
||
|
|
||
|
set local "$line[1]"
|
||
|
set system "$line[2]"
|
||
|
|
||
|
echo $local → $system
|
||
|
|
||
|
rm -rf "$system"
|
||
|
ln -s "$DOTFILES_REPO"/"$local" "$system"
|
||
|
end
|
||
|
end
|
||
|
|
||
|
if test "$argv[1]" = "add"
|
||
|
add_dotfiles $argv[2..-1]
|
||
|
else if test "$argv[1]" = "build"
|
||
|
restore_system $argv[2..-1]
|
||
|
end
|