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=(
|
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
|
||||||
|
|
|
@ -16,17 +16,19 @@ complete -F _dote_completions ".e"
|
||||||
|
|
||||||
_dott_completions()
|
_dott_completions()
|
||||||
{
|
{
|
||||||
if [ "${#COMP_WORDS[@]}" == "1" ]; then
|
if [ "${#COMP_WORDS[@]}" == "2" ]; then
|
||||||
return
|
COMPREPLY=()
|
||||||
|
while IFS='' read -r line
|
||||||
|
do
|
||||||
|
COMPREPLY+=("$line")
|
||||||
|
done < <(compgen -W "$(.t -l)" "${COMP_WORDS[1]}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
COMPREPLY=()
|
if [ "${#COMP_WORDS[@]}" == "3" ]; then
|
||||||
while IFS='' read -r line
|
compgen -f "${COMP_WORDS[2]}"
|
||||||
do
|
fi
|
||||||
COMPREPLY+=("$line")
|
|
||||||
done < <(compgen -W "$(.t -l)" "${COMP_WORDS[1]}")
|
|
||||||
}
|
}
|
||||||
complete -F _dott_completions ".t"
|
complete -o filenames -F _dott_completions ".t"
|
||||||
|
|
||||||
_autostart_manage_completions()
|
_autostart_manage_completions()
|
||||||
{
|
{
|
||||||
|
|
1
.config/templates/nix/.envrc
Normal file
1
.config/templates/nix/.envrc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
use nix
|
5
.config/templates/nix/shell.nix
Normal file
5
.config/templates/nix/shell.nix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
with import <nixpkgs> {};
|
||||||
|
mkShell {
|
||||||
|
nativeBuildInputs = [
|
||||||
|
];
|
||||||
|
}
|
3
.config/templates/sh
Executable file
3
.config/templates/sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue