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=( declare -A mapper=(
["nix"]="nix" ["nix"]="nix"
["sh"]="sh"
) )
declare -A edit_file=( declare -A edit_file=(
@ -20,28 +21,36 @@ then
exit exit
fi fi
target="${mapper["$1"]}" dest="."
if [ -z "$target" ] if [ -n "$2" ]
then
dest="$2"
fi
source="${mapper["$1"]}"
if [ -z "$source" ]
then then
echo "Template not found. Use --list (-l) to show all options." echo "Template not found. Use --list (-l) to show all options."
exit 1 exit 1
fi fi
target="$XDG_CONFIG_HOME/templates/$target" source="$XDG_CONFIG_HOME/templates/$source"
if [ -f "$target" ] if [ -f "$source" ]
then then
cp -i "$target" . cp -i "$source" "$dest"
echo "Template copied." echo "Template copied."
elif [ -d "$target" ] source_edit=$dest
elif [ -d "$source" ]
then then
cp -irT "$target" . cp -irT "$source" "$dest"
echo "Template copied." echo "Template copied."
source_edit=$dest/${edit_file["$1"]}
else else
echo "Error copying template." echo "Error copying template."
exit 1 exit 1
fi fi
if [ -n "${edit_file["$1"]}" ] if [ -n "$source_edit" ]
then then
$EDITOR "${edit_file["$1"]}" $EDITOR "$source_edit"
fi fi

View file

@ -16,17 +16,19 @@ complete -F _dote_completions ".e"
_dott_completions() _dott_completions()
{ {
if [ "${#COMP_WORDS[@]}" == "1" ]; then if [ "${#COMP_WORDS[@]}" == "2" ]; then
return
fi
COMPREPLY=() COMPREPLY=()
while IFS='' read -r line while IFS='' read -r line
do do
COMPREPLY+=("$line") COMPREPLY+=("$line")
done < <(compgen -W "$(.t -l)" "${COMP_WORDS[1]}") done < <(compgen -W "$(.t -l)" "${COMP_WORDS[1]}")
fi
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() _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