function tmpdir --description "cd into a fresh, one-time temporary directory"
  if not set --global --query TMPDIR_TAB
    mkdir -p /tmp/tmpdir
    set --global --export TMPDIR_TAB (mktemp -d /tmp/tmpdir/XXXXXX)
  end
  cd $TMPDIR_TAB
end


function _tmpdir_on_exit --on-process-exit %self
  if set --global --query TMPDIR_TAB
    rm -rf $TMPDIR_TAB
  end
end

function tmpdir --description "cd into a fresh, one-time temporary directory"
  if set --global --query TMPDIR_TAB
    cd $TMPDIR_TAB
    rm -- {.*,*}
  else
    mkdir -p /tmp/tmpdir
    set --global TMPDIR_TAB (mktemp -d /tmp/tmpdir/XXXXXX)
    cd $TMPDIR_TAB
  end
end


function _tmpdir_on_exit --on-process-exit %self
  if set --global --query TMPDIR_TAB
    rm -rf $TMPDIR_TAB
  end
end

Fix subshells / same shell behavior
Fix subshells / same shell behavior

eush77/fish-tmpdir