.dotfiles/.bin/.t

57 lines
826 B
Perl
Raw Normal View History

2023-10-30 21:50:18 +00:00
#!/usr/bin/env bash
declare -A mapper=(
["nix"]="nix"
2023-12-19 22:59:30 +00:00
["sh"]="sh"
2023-10-30 21:50:18 +00:00
)
declare -A edit_file=(
["nix"]="shell.nix"
)
if [ -z "$1" ]
then
echo "No argument given. Use --list (-l) to show all options."
exit 1
fi
if [ "$1" = "-l" ] || [ "$1" = "--list" ]
then
echo "${!mapper[@]}"
exit
fi
2023-12-19 22:59:30 +00:00
dest="."
if [ -n "$2" ]
then
dest="$2"
fi
source="${mapper["$1"]}"
if [ -z "$source" ]
2023-10-30 21:50:18 +00:00
then
echo "Template not found. Use --list (-l) to show all options."
exit 1
fi
2023-12-19 22:59:30 +00:00
source="$XDG_CONFIG_HOME/templates/$source"
if [ -f "$source" ]
2023-10-30 21:50:18 +00:00
then
2023-12-19 22:59:30 +00:00
cp -i "$source" "$dest"
2023-10-30 21:50:18 +00:00
echo "Template copied."
2023-12-19 22:59:30 +00:00
source_edit=$dest
elif [ -d "$source" ]
2023-10-30 21:50:18 +00:00
then
2023-12-19 22:59:30 +00:00
cp -irT "$source" "$dest"
2023-10-30 21:50:18 +00:00
echo "Template copied."
2023-12-19 22:59:30 +00:00
source_edit=$dest/${edit_file["$1"]}
2023-10-30 21:50:18 +00:00
else
echo "Error copying template."
exit 1
fi
2023-12-19 22:59:30 +00:00
if [ -n "$source_edit" ]
2023-10-30 21:50:18 +00:00
then
2023-12-19 22:59:30 +00:00
$EDITOR "$source_edit"
2023-10-30 21:50:18 +00:00
fi