This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/common/bin/dotfiles-link-environments

40 lines
813 B
Plaintext
Raw Normal View History

#!/usr/bin/env fish
2021-03-25 09:04:51 -05:00
2021-11-03 12:43:32 -05:00
has_command fzf || begin
echo "fzf not installed"
exit 1
2021-03-25 09:04:51 -05:00
end
2021-11-03 12:43:32 -05:00
2021-05-10 13:29:39 -05:00
mkdir -p $ENV_PATH
2021-11-03 12:43:32 -05:00
function filter_existing_directory
2021-11-03 12:52:33 -05:00
while read -l line
test -d $DOTFILES_PATH/$line && echo $line
2021-11-03 12:43:32 -05:00
end
2021-03-25 09:04:51 -05:00
end
2021-11-03 12:43:32 -05:00
function reject_empty_lines
2021-11-03 12:52:33 -05:00
while read -l line
test $line = "" || echo $line
2021-11-03 12:43:32 -05:00
end
end
function link
2021-11-03 12:52:33 -05:00
while read -l line
set safe_fn (string replace -a / - $line)
echo "Linking $ENV_PATH/$safe_fn to $DOTFILES_PATH/$line"
2021-11-03 12:43:32 -05:00
rm -f $ENV_PATH/$safe_fn
2021-11-03 12:52:33 -05:00
ln -s $DOTFILES_PATH/$line $ENV_PATH/$safe_fn
2021-11-03 12:43:32 -05:00
end
end
cat $DOTFILES_PATH/common/envs |
filter_existing_directory |
fzf --multi \
--prompt "Select applicable environments (multi-select w/ TAB): " \
--preview-window="up:50%:noborder" \
--preview="ls -la --color=always $DOTFILES_PATH/{}" |
string trim |
reject_empty_lines |
link