1
0
Fork 0
dotfiles/.local/bin/shortcuts

30 lines
1.6 KiB
Plaintext
Raw Normal View History

2022-07-04 21:36:33 +02:00
#!/bin/sh
bmdirs="${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs"
bmfiles="${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-files"
2022-10-21 17:52:11 +02:00
# Output locations
2022-07-04 21:36:33 +02:00
shell_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc"
zsh_named_dirs="${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc"
2022-09-30 13:11:15 +02:00
lf_files="${XDG_DATA_HOME:-$HOME/.local/share}/lf/shortcut-files"
lf_dirs="${XDG_DATA_HOME:-$HOME/.local/share}/lf/shortcut-dirs"
2022-10-21 17:52:11 +02:00
lf_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/lf/shortcutrc"
2022-07-04 21:36:33 +02:00
# Remove, prepare files
2022-10-27 09:37:21 +02:00
rm -f "$shell_shortcuts" "$lf_files" "$lf_dirs" "$lf_shortcuts" "$zsh_named_dirs" 2>/dev/null
2023-02-07 17:19:53 +01:00
printf "# vim: filetype=sh\\nalias " >"$shell_shortcuts"
2022-07-04 21:36:33 +02:00
# Format the `directories` file in the correct syntax and sent it to all three configs.
2022-10-21 17:52:11 +02:00
eval "echo \"$(cat "$bmdirs")\"" | awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\");
2022-10-22 16:35:17 +02:00
printf(\"%s=\42cd %s && tput cuu1;tput el\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ;
printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ;
2022-10-21 17:52:11 +02:00
printf(\"map g%s cd \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" ;
2022-10-22 16:35:17 +02:00
printf(\"%s\n\",\$2) >> \"$lf_dirs\" }"
2022-07-04 21:36:33 +02:00
# Format the `files` file in the correct syntax and sent it to both configs.
2022-10-21 17:52:11 +02:00
eval "echo \"$(cat "$bmfiles")\"" | awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\");
2022-10-22 16:35:17 +02:00
printf(\"%s=\42\$EDITOR %s\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ;
printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ;
printf(\"%s\n\",\$2) >> \"$lf_files\" ;
2022-10-27 09:37:21 +02:00
printf(\"map E%s \$\$EDITOR \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" }"