wont cd on exit
pfr-dev opened this issue · 10 comments
I might be doing something wrong here, but I can't get shfm to cd into the working directory on exit.
I've tried a few different things, but with the suggested method of adding this to the shellrc file (in mycase .shrc)(ksh)
shfm() {
cd "$(command shfm "$@")"
}
I get a pwd output on exit but I end up back in my home dir. I imagine I need to replace "command" with an actual command?
I'd also like to shorten it to sf so I tried:
sf() {
shfm "$@"
cd "$(command shfm "$@")"
}
I even tried running it with cd $(shfm)
which also prints out the working dir but does not cd into it.
Truth be told, I'm not very familiar with shell functions and am a bit of a noob so go easy on me.
Cheers :)
EDIT: Curiously, I noticed in the keybinds that !
"spawns a terminal" into the current directory but is it really spawning a terminal or is it just returning to the terminal whilst staying in the current directory? Anyhow, I suppose this can be my workaround for now but for the sake of clarity would still like to know how to resolve this.
While I'd still like to know how to resolve this, I only just realised that shfm
doesn't support file operations and it is therefore not going to suit my needs. I'll continue using fff
until hopefully one day shfm
has this functionality and can replace it.
:)
I added file operations to my fork of shfm if you'd like to try it out. I've been using it as my daily file manager for months so it's pretty stable. https://github.com/Sketch98/shfm
Regarding your original question, in my shellrc i have:
s() {
dest="$(dash $HOME/repos/shfm/shfm)"
[ "$dest" != "$PWD" ] && cd "$dest"
}
because i have multiple copies of shfm (stable one and dev one) and checking against PWD saves my old working directory if i wanna cd -
. If you put shfm in your path you can use:
s() {
cd "$(shfm "$@")"
}
Also, !
creates a new shell instance. Try opening a new shell in shfm with !
and repeat this several times. If you look at pstree, you'll notice a long line of bash and dash ending in dd. (assuming your default shell is bash)
I added file operations to my fork of shfm if you'd like to try it out. I've been using it as my daily file manager for months so it's pretty stable. https://github.com/Sketch98/shfm
Awesome, Thanks!
I wondered how hard it would be to incorporate image previews using ueberzug
into shfm
however your patch for sxiv
is even better considering I use a wm that uses frames instead of window swallowing. Do you think you'll merge this patch?
Regarding your original question
If you put shfm in your path you can use:s() { cd "$(shfm "$@")" }
This still wont work for me. I have your version of shfm
in my path /usr/local/bin/
and when exiting it prints the dir you were just in but wont cd into it.
can you try
s() {
dest="$(dash /path/to/shfm "$@")"
[ "$dest" != "$PWD" ] && cd "$dest"
}
i have no idea why this would make any difference, but it's what i use and it cd's on exit
can you try
s() { dest="$(dash /path/to/shfm "$@")" [ "$dest" != "$PWD" ] && cd "$dest" }
i have no idea why this would make any difference, but it's what i use and it cd's on exit
So strange! I'm using ksh
as my shell but I have bash
installed. I've tried this with both bash and ksh but neither will cd on exit!
i'm going to try out writing the directory to a temp file on exit like nnn does to see if that solves cd-on-exit, but my laptop is busy building my kiss os so that'll have to wait til tomorrow.
I wondered how hard it would be to incorporate image previews using
ueberzug
intoshfm
however your patch forsxiv
is even better considering I use a wm that uses frames instead of window swallowing. Do you think you'll merge this patch?
I don't think it'd be hard to add ueberzug support, but i'm planning to leave non-posix stuff in patches. The problem is, it's annoying to have to repatch or merge after every pull. I think I a post-receive hook might solve that, but i've never used hooks before so idk.
i'm going to try out writing the directory to a temp file on exit like nnn does to see if that solves cd-on-exit, but my laptop is busy building my kiss os so that'll have to wait til tomorrow.
No worries, I'm keen to figure this out because it will absolutely replace fff
for good then!
I don't think it'd be hard to add ueberzug support, but i'm planning to leave non-posix stuff in patches. The problem is, it's annoying to have to repatch or merge after every pull. I think I a post-receive hook might solve that, but i've never used hooks before so idk.
That's fair enough. I've forked your fork so I can just merge the patches and pull from my own repo if I want.
i'm going to try out writing the directory to a temp file on exit like nnn does to see if that solves cd-on-exit, but my laptop is busy building my kiss os so that'll have to wait til tomorrow.
Any luck with this?
oh yea i pushed it a while ago
oh yea i pushed it a while ago
Excellent, it works!
Would you be able to allow opening issues on your repo so I can discuss other issues in the future?