|  | @@ -18,12 +18,17 @@ fn get-hash {|@a|
 | 
											
												
													
														|  |    str:trim-right (echo $dir | sha256sum) "- "
 |  |    str:trim-right (echo $dir | sha256sum) "- "
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -fn state-type {
 |  | 
 | 
											
												
													
														|  | -  if (path:is-regular "flake.nix") {
 |  | 
 | 
											
												
													
														|  | 
 |  | +fn state-type {|@a|
 | 
											
												
													
														|  | 
 |  | +  var dir = $pwd
 | 
											
												
													
														|  | 
 |  | +  if (> (count $a) 0) {
 | 
											
												
													
														|  | 
 |  | +    set dir = $a[0]
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +  if (path:is-regular $dir"/flake.nix") {
 | 
											
												
													
														|  |      put "nix"
 |  |      put "nix"
 | 
											
												
													
														|  | -  } elif (path:is-regular "shell.nix") {
 |  | 
 | 
											
												
													
														|  | 
 |  | +  } elif (path:is-regular $dir"/shell.nix") {
 | 
											
												
													
														|  |      put "nix"
 |  |      put "nix"
 | 
											
												
													
														|  | -  } elif (path:is-regular "default.nix") {
 |  | 
 | 
											
												
													
														|  | 
 |  | +  } elif (path:is-regular $dir"/default.nix") {
 | 
											
												
													
														|  |      put "nix"
 |  |      put "nix"
 | 
											
												
													
														|  |    } else {
 |  |    } else {
 | 
											
												
													
														|  |      put $nil
 |  |      put $nil
 | 
											
										
											
												
													
														|  | @@ -138,27 +143,32 @@ fn env-from-nix-flake {|state-file|
 | 
											
												
													
														|  |    }
 |  |    }
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -fn push-dir {|type state-file|
 |  | 
 | 
											
												
													
														|  | -  var env = []
 |  | 
 | 
											
												
													
														|  | -  if (eq $type "nix") {
 |  | 
 | 
											
												
													
														|  | -    set @env = (env-from-nix-flake $state-file)
 |  | 
 | 
											
												
													
														|  | -  }
 |  | 
 | 
											
												
													
														|  | 
 |  | +fn push-dir {|type state-file path|
 | 
											
												
													
														|  | 
 |  | +  var env-diff = $nil
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  var @env-diff = (diff-env $env)
 |  | 
 | 
											
												
													
														|  | 
 |  | +  if (not-eq $state-file $nil) {
 | 
											
												
													
														|  | 
 |  | +    var env = []
 | 
											
												
													
														|  | 
 |  | +    if (eq $type "nix") {
 | 
											
												
													
														|  | 
 |  | +      set @env = (env-from-nix-flake $state-file)
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  var entry = [&dir=$pwd &env-diff=$env-diff]
 |  | 
 | 
											
												
													
														|  | 
 |  | +    set @env-diff = (diff-env $env)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  edit:notify "Entered direlv "$pwd
 |  | 
 | 
											
												
													
														|  | -  edit:notify (print (apply-env $env))
 |  | 
 | 
											
												
													
														|  | 
 |  | +    edit:notify "Entered direlv "$path
 | 
											
												
													
														|  | 
 |  | +    edit:notify (print (apply-env $env))
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +  var entry = [&dir=$path &env-diff=$env-diff]
 | 
											
												
													
														|  |    set dir-stack = [ $entry $@dir-stack ]
 |  |    set dir-stack = [ $entry $@dir-stack ]
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  fn pop-dir {
 |  |  fn pop-dir {
 | 
											
												
													
														|  |    var last = $dir-stack[0]
 |  |    var last = $dir-stack[0]
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  edit:notify "Exited direlv "$last[dir]
 |  | 
 | 
											
												
													
														|  | -  edit:notify (print (apply-env $last[env-diff]))
 |  | 
 | 
											
												
													
														|  | 
 |  | +  if (not-eq $last[env-diff] $nil) {
 | 
											
												
													
														|  | 
 |  | +    edit:notify "Exited direlv "$last[dir]
 | 
											
												
													
														|  | 
 |  | +    edit:notify (print (apply-env $last[env-diff]))
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |    set dir-stack = $dir-stack[1..]
 |  |    set dir-stack = $dir-stack[1..]
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
										
											
												
													
														|  | @@ -209,7 +219,7 @@ edit:add-var direlv~ {|@a|
 | 
											
												
													
														|  |      if (eq $dir $pwd) {
 |  |      if (eq $dir $pwd) {
 | 
											
												
													
														|  |        pop-dir
 |  |        pop-dir
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | -    push-dir $type $state-file
 |  | 
 | 
											
												
													
														|  | 
 |  | +    push-dir $type $state-file $pwd
 | 
											
												
													
														|  |    } elif (eq $a[0] "clear") {
 |  |    } elif (eq $a[0] "clear") {
 | 
											
												
													
														|  |      var dir = (current-dir)
 |  |      var dir = (current-dir)
 | 
											
												
													
														|  |      if (not-eq $dir $nil) {
 |  |      if (not-eq $dir $nil) {
 | 
											
										
											
												
													
														|  | @@ -231,16 +241,38 @@ fn on-chdir {|dir|
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |    }
 |  |    }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  var type = (state-type)
 |  | 
 | 
											
												
													
														|  | -  if (eq $type $nil) {
 |  | 
 | 
											
												
													
														|  | -    return
 |  | 
 | 
											
												
													
														|  | 
 |  | +  var last = "/"
 | 
											
												
													
														|  | 
 |  | +  if (> (count $dir-stack) 0) {
 | 
											
												
													
														|  | 
 |  | +    set last = $dir-stack[0][dir]
 | 
											
												
													
														|  |    }
 |  |    }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  var hash = (get-hash)
 |  | 
 | 
											
												
													
														|  | -  var state-file = $state-dir/$hash'-'$type
 |  | 
 | 
											
												
													
														|  | 
 |  | +  var current = $pwd
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +  var candidates = []
 | 
											
												
													
														|  | 
 |  | +  while (and (str:has-prefix $current $last) (not-eq $current $last)) {
 | 
											
												
													
														|  | 
 |  | +    set candidates = [ $current $@candidates ]
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    if (eq $current "/") {
 | 
											
												
													
														|  | 
 |  | +      # put this at the end so it can run against `/` once
 | 
											
												
													
														|  | 
 |  | +      break
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +    set current = (path:dir $current)
 | 
											
												
													
														|  | 
 |  | +  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  if (path:is-regular $state-file &follow-symlink=$true) {
 |  | 
 | 
											
												
													
														|  | -    push-dir $type $state-file
 |  | 
 | 
											
												
													
														|  | 
 |  | +  for candidate $candidates {
 | 
											
												
													
														|  | 
 |  | +    var type = (state-type $candidate)
 | 
											
												
													
														|  | 
 |  | +    if (not-eq $type $nil) {
 | 
											
												
													
														|  | 
 |  | +      var hash = (get-hash $candidate)
 | 
											
												
													
														|  | 
 |  | +      var state-file = $state-dir/$hash'-'$type
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +      if (path:is-regular $state-file &follow-symlink=$true) {
 | 
											
												
													
														|  | 
 |  | +        push-dir $type $state-file $candidate
 | 
											
												
													
														|  | 
 |  | +      } else {
 | 
											
												
													
														|  | 
 |  | +        push-dir $type $nil $candidate
 | 
											
												
													
														|  | 
 |  | +      }
 | 
											
												
													
														|  | 
 |  | +    } else {
 | 
											
												
													
														|  | 
 |  | +      push-dir "none" $nil $candidate
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |    }
 |  |    }
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 |