Code Monkey home page Code Monkey logo

Comments (6)

kamiyaa avatar kamiyaa commented on May 22, 2024 1

new command added: quit_to_cwd
This will write the current directory to a file specified by the --lastdir command line option.
Then the function I mentioned above will go to that directory upon quiting joshuto

commit: f8851c7

from joshuto.

jtrv avatar jtrv commented on May 22, 2024 1

This is excellent! The only change I would make (and I don't mean to be nitpicky) would be to change the name from --lastdir to --last-dir just to separate the two words and keep a regular naming-convention for flags. Maybe we could add a shorthand version -l as well, if we want to type less. Thank you again and I appreciate the quick turnaround!

from joshuto.

kamiyaa avatar kamiyaa commented on May 22, 2024

You can currently do this via an alias:

alias joshut='joshuto --lastdir /tmp/$USER/joshuto-lastdir;
	LASTDIR="$(cat /tmp/$USER/joshuto-lastdir)";
	[ "$LASTDIR" != "$(pwd)" ] && cd "$LASTDIR"';

This is not optional though; you will always cd to the current directory in Joshuto on exit.
But you can go back with cd -

If you want it to be optional, we can potentially modify the exit code to indicate to our shell that we want to move to the specified directory. ie. exit code 2 means cd to the current directory in Joshuto

from joshuto.

jtrv avatar jtrv commented on May 22, 2024

Hmm that sounds sort of hacky, maybe this function from hunter might be helpful in finding a solution:
https://github.com/rabite0/hunter/blob/355d9a3101f6d8dc375807de79e368602f1cb87d/src/file_browser.rs#L931

from joshuto.

kamiyaa avatar kamiyaa commented on May 22, 2024

Yea, we can implement a command like hunter to QuitToCwd.

Then have a bash function to facilitate it like hunter. This is what I currently have atm:

function joshuto() {
	CWD_FILE="/tmp/$USER/joshuto-cwd"
	env joshuto --lastdir "$CWD_FILE" $@

	if [ -e "$CWD_FILE" ]; then
		JOSHUTO_CWD=$(cat "$CWD_FILE")
		rm "$CWD_FILE" && cd "$JOSHUTO_CWD"
	fi
}

I will be adding QuitToCwd shortly.
I don't think I will be adding all the additional options hunter has (at least for now) just because I don't think it will work well with files with spaces or other special characters (without more work).
ie.

HUNTER_CWD=...
F=...
MF=...

We can also move --lastdir into an option in the config instead of a command line parameter, but that can be for the future

from joshuto.

kamiyaa avatar kamiyaa commented on May 22, 2024

changed to --last-dir in dev branch fcf869c.

I've decided to not add -l just because I think it might be used for a different option in the future and --last-dir seems like a non-intuitive option to have a shorthand version for.

Also, updated the script so it would take timestamps into account when creating these files to reduce collisions.

function joshuto() {
	TIMESTAMP=$(date '+%Y%m%d-%H%M%S')
	CWD_FILE="/tmp/$USER/joshuto-cwd-$TIMESTAMP"
	env joshuto --last-dir "$CWD_FILE" $@

	if [ -e "$CWD_FILE" ]; then
		JOSHUTO_CWD=$(cat "$CWD_FILE")
		rm "$CWD_FILE" && cd "$JOSHUTO_CWD"
	fi
}

from joshuto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.