Improve .t script
This commit is contained in:
parent
d173de93ba
commit
717d35f2b0
5 changed files with 37 additions and 17 deletions
27
.bin/.t
27
.bin/.t
|
@ -2,6 +2,7 @@
|
|||
|
||||
declare -A mapper=(
|
||||
["nix"]="nix"
|
||||
["sh"]="sh"
|
||||
)
|
||||
|
||||
declare -A edit_file=(
|
||||
|
@ -20,28 +21,36 @@ then
|
|||
exit
|
||||
fi
|
||||
|
||||
target="${mapper["$1"]}"
|
||||
if [ -z "$target" ]
|
||||
dest="."
|
||||
if [ -n "$2" ]
|
||||
then
|
||||
dest="$2"
|
||||
fi
|
||||
|
||||
source="${mapper["$1"]}"
|
||||
if [ -z "$source" ]
|
||||
then
|
||||
echo "Template not found. Use --list (-l) to show all options."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
target="$XDG_CONFIG_HOME/templates/$target"
|
||||
if [ -f "$target" ]
|
||||
source="$XDG_CONFIG_HOME/templates/$source"
|
||||
if [ -f "$source" ]
|
||||
then
|
||||
cp -i "$target" .
|
||||
cp -i "$source" "$dest"
|
||||
echo "Template copied."
|
||||
elif [ -d "$target" ]
|
||||
source_edit=$dest
|
||||
elif [ -d "$source" ]
|
||||
then
|
||||
cp -irT "$target" .
|
||||
cp -irT "$source" "$dest"
|
||||
echo "Template copied."
|
||||
source_edit=$dest/${edit_file["$1"]}
|
||||
else
|
||||
echo "Error copying template."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "${edit_file["$1"]}" ]
|
||||
if [ -n "$source_edit" ]
|
||||
then
|
||||
$EDITOR "${edit_file["$1"]}"
|
||||
$EDITOR "$source_edit"
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue