Add .t for template copying
This commit is contained in:
		
							parent
							
								
									99dfe95131
								
							
						
					
					
						commit
						478f6722ba
					
				
					 3 changed files with 69 additions and 12 deletions
				
			
		
							
								
								
									
										20
									
								
								.bin/.e
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								.bin/.e
									
										
									
									
									
								
							|  | @ -8,6 +8,7 @@ declare -A mapper=( | ||||||
| 	["autostart.toml"]="$HOME/.config/autostart.toml" | 	["autostart.toml"]="$HOME/.config/autostart.toml" | ||||||
| 	["bash"]="$HOME/.bashrc" | 	["bash"]="$HOME/.bashrc" | ||||||
| 	["bspwm"]="$HOME/.config/bspwm/bspwmrc" | 	["bspwm"]="$HOME/.config/bspwm/bspwmrc" | ||||||
|  | 	["completions"]="$HOME/.config/completionsrc" | ||||||
| 	["env"]="$HOME/.config/environment" | 	["env"]="$HOME/.config/environment" | ||||||
| 	["env.d"]="$HOME/.config/env.d/" | 	["env.d"]="$HOME/.config/env.d/" | ||||||
| 	["git"]="$HOME/.config/git/config" | 	["git"]="$HOME/.config/git/config" | ||||||
|  | @ -22,7 +23,7 @@ declare -A mapper=( | ||||||
| 	["starship"]="$HOME/.config/starship.toml" | 	["starship"]="$HOME/.config/starship.toml" | ||||||
| 	["sxhkd"]="$HOME/.config/sxhkd/sxhkdrc" | 	["sxhkd"]="$HOME/.config/sxhkd/sxhkdrc" | ||||||
| 	["vim"]="$HOME/.config/vim/vimrc" | 	["vim"]="$HOME/.config/vim/vimrc" | ||||||
| 	["wakatime"]="$HOME/.config/wakatime/.wakatime.cfg.tpl" | 	["wakatime"]="$HOME/.config/wakatime/.wakatime.cfg##template" | ||||||
| 	["waybar"]="$HOME/.config/waybar/" | 	["waybar"]="$HOME/.config/waybar/" | ||||||
| 	["xprofile"]="$HOME/.xprofile" | 	["xprofile"]="$HOME/.xprofile" | ||||||
| 	["yadm-encrypt"]="$HOME/.config/yadm/encrypt" | 	["yadm-encrypt"]="$HOME/.config/yadm/encrypt" | ||||||
|  | @ -32,24 +33,19 @@ declare -A mapper=( | ||||||
| if [ -z "$1" ] | if [ -z "$1" ] | ||||||
| then | then | ||||||
| 	echo "No argument given. Use --list (-l) to show all options." | 	echo "No argument given. Use --list (-l) to show all options." | ||||||
| 	exit | 	exit 1 | ||||||
| fi | fi | ||||||
| if [ "$1" = "-l" ] || [ "$1" = "--list" ] | if [ "$1" = "-l" ] || [ "$1" = "--list" ] | ||||||
| then | then | ||||||
| 	echo "${!mapper[@]}" | 	echo "${!mapper[@]}" | ||||||
| 	exit | 	exit 0 | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| target="${mapper["$1"]}" | target="${mapper["$1"]}" | ||||||
| if [ -n "$target" ] | if [ -z "$target" ] | ||||||
| then | then | ||||||
| 	if [ -d "$target" ] |  | ||||||
| 	then |  | ||||||
| 		cd "$target" |  | ||||||
| 		$EDITOR . |  | ||||||
| 	else |  | ||||||
| 		$EDITOR "$target" |  | ||||||
| 	fi |  | ||||||
| else |  | ||||||
| 	echo "Dotfile not found. Use --list (-l) to show all options." | 	echo "Dotfile not found. Use --list (-l) to show all options." | ||||||
|  | 	exit 1 | ||||||
| fi | fi | ||||||
|  | 
 | ||||||
|  | $EDITOR "$target" | ||||||
|  |  | ||||||
							
								
								
									
										47
									
								
								.bin/.t
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										47
									
								
								.bin/.t
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,47 @@ | ||||||
|  | #!/usr/bin/env bash | ||||||
|  | 
 | ||||||
|  | declare -A mapper=( | ||||||
|  | 	["nix"]="nix" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | 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 | ||||||
|  | 
 | ||||||
|  | target="${mapper["$1"]}" | ||||||
|  | if [ -z "$target" ] | ||||||
|  | then | ||||||
|  | 	echo "Template not found. Use --list (-l) to show all options." | ||||||
|  | 	exit 1 | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | target="$XDG_CONFIG_HOME/templates/$target" | ||||||
|  | if [ -f "$target" ] | ||||||
|  | then | ||||||
|  | 	cp "$target" . | ||||||
|  | 	echo "Template copied." | ||||||
|  | elif [ -d "$target" ] | ||||||
|  | then | ||||||
|  | 	cp -r "$target/*" . | ||||||
|  | 	echo "Template copied." | ||||||
|  | else | ||||||
|  | 	echo "Error copying template." | ||||||
|  | 	exit 1 | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | if [ -n "${edit_file["$1"]}" ] | ||||||
|  | then | ||||||
|  | 	$EDITOR "${edit_file["$1"]}" | ||||||
|  | fi | ||||||
|  | @ -14,6 +14,20 @@ _dote_completions() | ||||||
| } | } | ||||||
| complete -F _dote_completions ".e" | complete -F _dote_completions ".e" | ||||||
| 
 | 
 | ||||||
|  | _dott_completions() | ||||||
|  | { | ||||||
|  | 	if [ "${#COMP_WORDS[@]}" == "1" ]; then | ||||||
|  | 		return | ||||||
|  | 	fi | ||||||
|  | 
 | ||||||
|  | 	COMPREPLY=() | ||||||
|  | 	while IFS='' read -r line | ||||||
|  | 	do | ||||||
|  | 		COMPREPLY+=("$line") | ||||||
|  | 	done < <(compgen -W "$(.t -l)" "${COMP_WORDS[1]}") | ||||||
|  | } | ||||||
|  | complete -F _dott_completions ".t" | ||||||
|  | 
 | ||||||
| _autostart_manage_completions() | _autostart_manage_completions() | ||||||
| { | { | ||||||
| 	if [ "${#COMP_WORDS[@]}" == "2" ]; then | 	if [ "${#COMP_WORDS[@]}" == "2" ]; then | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue