Dotfiles for my tiling window manager + terminal workflow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9 KiB

5 years ago
  1. #!/bin/bash
  2. # ensure {{{ #
  3. # Ensure text of argument 1 exists in the file argument 2
  4. ensure() {
  5. if [[ ! -e "$2" ]]; then
  6. touch "$2"
  7. fi
  8. (grep "$1" "$2")>/dev/null 2>&1 || echo "$1" >> "$2"
  9. }
  10. # }}} ensure #
  11. # config files
  12. bashrc="$HOME/.bashrc"
  13. zshrc="$HOME/.zshrc"
  14. fish_config="$HOME/.config/fish/config.fish"
  15. ranger_config="$HOME/.config/ranger/rc.conf"
  16. # Output locations
  17. aliases="$HOME/aliases/.key_aliases"
  18. fish_abbr="$HOME/.config/fish/key_abbr.fish"
  19. ranger_mappings="$HOME/.config/ranger/key_mappings.conf"
  20. # ensure sourcing new file in orig. config file
  21. ensure "source $aliases" "$bashrc"
  22. ensure "source $aliases" "$zshrc"
  23. # ensure "source $fish_abbr" "$fish_config"
  24. ensure "source $ranger_mappings" "$ranger_config"
  25. # key files
  26. key_dirs="$HOME/aliases/key_dirs"
  27. key_files="$HOME/aliases/key_files"
  28. key_aliases="$HOME/aliases/key_aliases"
  29. # Remove, prepare files
  30. rm -f "$ranger_mappings" 2>/dev/null
  31. printf "# vim: filetype=sh\\n" > "$fish_abbr"
  32. printf "# vim: filetype=sh\\nalias " > "$aliases"
  33. # Format the key file in the correct syntax and sent it to all configs.
  34. sed "s/\s*#.*$//;/^\s*$/d" "$key_dirs" | tee \
  35. >(awk '{print $1"=\"cd "$2" && lsd -a\" \\"}' >> "$aliases") \
  36. >(awk '{print "abbr", $1, "\"cd", $2, "\""}' >> "$fish_abbr") \
  37. | awk '{print "map f"$1, "cd", $2;
  38. print "map t"$1, "tab_new", $2;
  39. print "map m"$1, "shell mv -v %f", $2;
  40. print "map Y"$1, "shell cp -rv %f", $2;
  41. }' >> "$ranger_mappings"
  42. sed "s/\s*#.*$//;/^\s*$/d" "$key_files" | tee \
  43. >(awk '{print n$1"=\"$EDITOR "$2"\" \\"}' >> "$aliases") \
  44. >(awk '{print "abbr n"$1, "\"$EDITOR "$2"\""}' >> "$fish_abbr") \
  45. | awk '{print "map n"$1" shell $EDITOR "$2}' >> "$ranger_mappings"
  46. sed -e '/^$/d' -e '/[ ]*#.*/d' "$key_aliases" | sort | tee \
  47. >(awk '{printf "abbr " $1; $1 = ""; print $0; }' >> "$fish_abbr") \
  48. | awk '{
  49. printf $1;
  50. $1 = "";
  51. printf "=";
  52. printf gensub(" ", "", 1, $0);
  53. print " \\";
  54. }' >> "$aliases"