config.elv 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. var max-len = 30
  28. # print time if command takes longer than 5 seconds
  29. set edit:after-command = [{|m|
  30. if (> $m[duration] 5) {
  31. var cmd = $m[src][code]
  32. var len = (count $cmd)
  33. if (> $len $max-len) {
  34. set cmd = $cmd[..$max-len]…
  35. }
  36. printf "%s took %.3fs\n" $cmd $m[duration]
  37. }
  38. }]
  39. eval (carapace _carapace|slurp)
  40. # restrict completion to only directories
  41. set edit:completion:arg-completer[cd] = $completion:dirs~
  42. # import local.elv if present, for example, from ~/.config/elvish/lib/local.elv
  43. try {
  44. use local
  45. } catch e {
  46. if (not (str:contains (to-string $e[reason]) "no such module")) {
  47. fail $e
  48. }
  49. }