config.elv 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. use str
  2. use prompt
  3. use nix-shell
  4. use title
  5. use eval-export
  6. use completion
  7. use pushd
  8. # don't use direlv if we're in a nix-shell to avoid nesting direlvs
  9. if (not (has-env IN_NIX_SHELL)) {
  10. use direlv
  11. }
  12. edit:add-var ls~ { |@a|
  13. e:ls --color=auto --group-directories-first -F --quoting-style literal $@a
  14. }
  15. if (has-external yadm) {
  16. set-env YADM_OVERRIDE_REPO ~/.dotfiles
  17. } else {
  18. edit:add-var yadm~ { |@a| git --git-dir=$E:HOME/.dotfiles/ --work-tree=$E:HOME $@a }
  19. }
  20. if (has-external delta) {
  21. set-env GIT_PAGER delta
  22. }
  23. # some additional bindings
  24. use readline-binding
  25. set edit:completion:binding[Ctrl-W] = $edit:close-mode~
  26. set edit:completion:binding[Tab] = $edit:completion:accept~
  27. set edit:location:binding[Ctrl-W] = $edit:kill-word-left~
  28. var max-len = 30
  29. # print time if command takes longer than 5 seconds
  30. set edit:after-command = [{|m|
  31. if (> $m[duration] 5) {
  32. var cmd = $m[src][code]
  33. var len = (count $cmd)
  34. if (> $len $max-len) {
  35. set cmd = $cmd[..$max-len]…
  36. }
  37. printf "%s took %.3fs\n" $cmd $m[duration]
  38. }
  39. }]
  40. eval (carapace _carapace|slurp)
  41. # restrict completion to only directories
  42. set edit:completion:arg-completer[cd] = $completion:dirs~
  43. # add dotfiles scripts
  44. set paths = [
  45. ~/.roaming/bin
  46. $@paths
  47. ]
  48. # import local.elv if present, for example, from ~/.config/elvish/lib/local.elv
  49. try {
  50. use local
  51. } catch e {
  52. if (not (str:contains (to-string $e[reason]) "no such module")) {
  53. fail $e
  54. }
  55. }