• hallettj@leminal.space
      link
      fedilink
      English
      arrow-up
      2
      ·
      16 hours ago

      I like mkcd! I have the same thing. Although what I use more is a function I pair with it that specifically creates a temporary directory, and cds to it. It’s useful for temporary work, like extracting from a zip file.

      These are my Nushell implementations:

      # Create a directory, and immediately cd into it.
      # The --env flag propagates the PWD environment variable to the caller, which is
      # necessary to make the directory change stick.
      def --env dir [dirname: string] {
        mkdir $dirname
        cd $dirname
      }
      
      # Create a temporary directory, and cd into it.
      def --env tmp [
        dirname?: string # the name of the directory - if omitted the directory is named randomly
      ] {
        if ($dirname != null) {
          dir $"/tmp/($dirname)"
        } else {
          cd (mktemp -d)
        }
      }