51 lines
1.2 KiB
Fish
51 lines
1.2 KiB
Fish
#!/usr/bin/env fish
|
|
|
|
set USER_DISAGREE_CODE 120
|
|
set NO_AGREEMENT_CODE 121
|
|
|
|
function dotfiles_setup_check_agreement
|
|
set -l lock_file $argv[1]
|
|
|
|
# Let user know that this script will delete their current configuration and
|
|
# that they should read this script before running. We'll use a lock file so
|
|
# the user only needs to agree once.
|
|
if test -f $lock_file
|
|
# User agreed already - do nothing
|
|
echo Lock file exists \($lock_file\)
|
|
echo Linking files...
|
|
else
|
|
echo This will delete existing files. Make sure you know what you\'re doing.
|
|
read -r -p "Are you sure you want to continue? [y/N] " response
|
|
set response (string lower $response)
|
|
if string match $response y
|
|
echo "agreed" > "$lock_file"
|
|
else
|
|
return $USER_DISAGREE_CODE
|
|
end
|
|
end
|
|
end
|
|
|
|
function l
|
|
set i $argv[2]
|
|
if test -L $i || test -f $i || test -d $i
|
|
rm -rf "$i"
|
|
end
|
|
# check if the directory that will contain the link exists
|
|
set -l d (dirname $i)
|
|
test -d $d || mkdir -p $d
|
|
ln -s $dfp/$argv[1] $i
|
|
echo Linked $argv[1] to $i
|
|
end
|
|
|
|
function dotfiles_setup_link_files
|
|
for i in $argv
|
|
if set -q source_file
|
|
l $source_file $i
|
|
set -e source_file
|
|
else
|
|
set source_file $i
|
|
end
|
|
end
|
|
echo Done.
|
|
end
|