Improve .t script

This commit is contained in:
Tobias Reisinger 2023-12-19 23:59:30 +01:00
parent d173de93ba
commit 717d35f2b0
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
5 changed files with 37 additions and 17 deletions

27
.bin/.t
View file

@ -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

View file

@ -16,17 +16,19 @@ complete -F _dote_completions ".e"
_dott_completions()
{
if [ "${#COMP_WORDS[@]}" == "1" ]; then
return
if [ "${#COMP_WORDS[@]}" == "2" ]; then
COMPREPLY=()
while IFS='' read -r line
do
COMPREPLY+=("$line")
done < <(compgen -W "$(.t -l)" "${COMP_WORDS[1]}")
fi
COMPREPLY=()
while IFS='' read -r line
do
COMPREPLY+=("$line")
done < <(compgen -W "$(.t -l)" "${COMP_WORDS[1]}")
if [ "${#COMP_WORDS[@]}" == "3" ]; then
compgen -f "${COMP_WORDS[2]}"
fi
}
complete -F _dott_completions ".t"
complete -o filenames -F _dott_completions ".t"
_autostart_manage_completions()
{

View file

@ -0,0 +1 @@
use nix

View file

@ -0,0 +1,5 @@
with import <nixpkgs> {};
mkShell {
nativeBuildInputs = [
];
}

3
.config/templates/sh Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env sh