瀏覽代碼

nixpkgs/elvish: add rudimentary popd implementation

Thomas Dy 1 年之前
父節點
當前提交
d929e247a1
共有 2 個文件被更改,包括 21 次插入0 次删除
  1. 1 0
      .config/nixpkgs/elvish/lib/config.elv
  2. 20 0
      .config/nixpkgs/elvish/lib/pushd.elv

+ 1 - 0
.config/nixpkgs/elvish/lib/config.elv

@@ -5,6 +5,7 @@ use direlv
 use title
 use eval-export
 use completion
+use pushd
 
 edit:add-var ls~ { |@a|
   e:ls --color=auto --group-directories-first -F --quoting-style literal $@a

+ 20 - 0
.config/nixpkgs/elvish/lib/pushd.elv

@@ -0,0 +1,20 @@
+var dir-stack = [$pwd]
+
+fn on-chdir {|dir|
+  var last = $dir-stack[0]
+  if (not-eq $dir $last) {
+    set dir-stack = [ $dir $@dir-stack ]
+  }
+}
+
+edit:add-var popd~ {||
+  if (> (count $dir-stack) 1) {
+    set dir-stack = $dir-stack[1..]
+    var last = $dir-stack[0]
+    cd $last
+  } else {
+    edit:notify "Reached bottom of directory stack"
+  }
+}
+
+set after-chdir = [$on-chdir~ $@after-chdir]