rabite0 / hunter

The fastest file manager in the galaxy!
Do What The F*ck You Want To Public License
1.32k stars 64 forks source link

Issue with exit on cd with fish shell #86

Open skewballfox opened 4 years ago

skewballfox commented 4 years ago

Hey, new user here. Just installed hunter via cargo for nightly. This probably isn't a bug so much as misconfiguration but I figured I'd bring it to your attention just in case it is.

I'm currently using fish shell on fedora and I'm trying to configure hunter to drop into last traversed directory on quit. I wrote an equivalent shell script for fish shell for hunter_cd.sh for fish:

function hunter
     env hunter
     if test -e $HOME/.hunter_cwd
        source $HOME/.hunter_cwd and \
        rm $HOME/.hunter_cwd and cd $HUNTER_CWD
    end
end

however it's not dropping into the directory. I suspect it's because $HOME/.hunter_cwd isn't being created, though I didn't see anything in the readme about needing to be created, so I assume this is suppose to be automatic. Any ideas what I'm doing wrong?

rabite0 commented 4 years ago

You need to press Q to enable this feature on quit. That should create this file.

Btw, mind if I add that function to the repo?

ohmree commented 3 years ago

The above solution didn't work for me since fish chokes on POSIX-style variable definitions (not if you export them first though, which could also be a solution but would require a modification to hunter).
What I ended up doing was parsing the file and using the result to set fish variables.

The code also had a subtle bug (at least I think so): rm $HOME/.hunter_cwd and #... needs to have a semicolon before the and, otherwise the rest of the line is seen as the argument list for rm.

Also env is unnecessary here, fish has the builtin command exactly for this purpose (I'm also running a few of the other commands using command because they're aliases on my machine).

With that in mind, here's my function:

function hunter
     command hunter
     if test -e $HOME/.hunter_cwd
         for line in (command cat ~/.hunter_cwd | string split '\n')
             set split (string split '=' $line)
             set $split[1] (string unescape $split[2])
         end
         command rm $HOME/.hunter_cwd; and cd $HUNTER_CWD
    end
end
ohmree commented 3 years ago

I do think a better solution would be to generate a separate file for fish, I've had a brief look at the code but couldn't find where exactly this happens on the master branch so I can't implement this myself.