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
2022-12-13 14:12:29 -06:00

39 lines
830 B
Fish
Executable file

#!/usr/bin/env fish
has_command sk || begin
echo "sk not installed (skim fuzzy finder)"
exit 1
end
mkdir -p $ENV_PATH
function filter_existing_directory
while read -l line
test -d $DOTFILES_PATH/$line && echo $line
end
end
function reject_empty_lines
while read -l line
test $line = "" || echo $line
end
end
function link
while read -l line
set safe_fn (string replace -a / - $line)
echo "Linking $ENV_PATH/$safe_fn to $DOTFILES_PATH/$line"
rm -f $ENV_PATH/$safe_fn
ln -s $DOTFILES_PATH/$line $ENV_PATH/$safe_fn
end
end
cat $DOTFILES_PATH/common/envs |
filter_existing_directory |
sk --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