New feature for Terminal!

I love using the Preferences->Shortcuts in Haiku. I also use Terminal quite often (all the time.) I like having custom Shortcuts to start Terminal. If this sounds like you, or could be you, then you might find the following interesting.

I found that using Shortcuts to open Terminal is ( now was) limited to winding up in the root directory “/”. Lame. Who wants to always start their Terminal journey there? Not me.

To remedy this, I spent a few hours this weekend playing with Terminal’s source code. I came up with a few lines of code that make it so you can pass a working directory to Terminal.

$ Terminal -w /boot/home/config/

will put your new Terminal in the /boot/home/config directory.

Or you could use:

$ Terminal --working-directory /boot/home/config/

I added the lines in -h/–help to document the feature for users. All that I have left to do is add checking to make sure that a valid directory is passed as the argument and some code cleanup. Then I’ll be submitting the code. As of right now, it will default to the current directory if an invalid directory is passed. This actually might be good enough, or even the preferred result. I haven’t decided.

What does everyone think? Would you use this? Did I waste my time? I don’t think so. I love it!

Why do all this work? You can already achieve the same result by just cd'ing to the directory you want and then starting Terminal from there. This is how the Open Terminal Tracker add-on can start a Terminal in the directory you invoke it from.

1 Like

In part it was an exercise for my self. I haven’t written much code lately, or ever. Mostly just reading code. It broke my funk. How do you cd within Preferences->Shortcuts? All I can get is “/”. Besides, cd is one extra command to execute. That was my prime reason for this. For that alone, it was worth it to me.

1 Like

Also the tracker add-on defaults to whatever is in focus in Tracker. With Terminal -w, you can set a Shortcut to open your favorite directories with a key stroke any time. Not just when Tracker is in focus. This would be a feature that would work in addition to the Tracker add-on.

2 Likes

Shortcuts command execution already runs through a shell, so the time for command parse + cd syscall is almost identically equivalent to argv parse + cd syscall in Terminal. There’s really no difference at all performance-wise.

Shorcuts won’t let me call cd.
Can't launch cd, no file exists. Please check your Shorcuts settings.
Would you prefer I had fixed this in Shorcuts instead of adding this feature to Terminal? If so, I will. I have a hunch that would be a simple matter of adding /boot/system/bin to Shortcuts’ $PATH.

Yes, Shortcuts should probably run commands in a shell.

2 Likes

I’ll work on that next. I’d ask you to reconsider the Terminal -w syntax. It’s more user intuitive in certain situations. That method wasn’t obvious to me while implementing the arg in Terminal.

In any case, I noticed some unimplemented features while poking around in the Terminal code. I might have to work on those too.

Poking around in Shortcuts’ code, the solution there is not as obvious as one would assume.

While you are at it an acutall filepicker instead of a textbox would be nice in shortcuts… or even a query window that you can search for applications and pick from etc… anything the current popup with a textbox in it could use some improvement.

2 Likes

The Shortcuts prefs are a worthy target for attention… have been for a long time. :slight_smile:

With regard to the Terminal, what do you guys think about adding a “Favorites” menu, showing the folders put in ~/config/settings/Tracker/Go, the same that’s also in all file dialogs?
I find it’s a relatively unknown feature that should be used more often.
Granted, the Terminal is a keyboard centric application, but I think I’d use that to access often needed deeply buried locations. Maybe add SHIFT+ALT+numberkey for quick access to the first 10.

3 Likes

Shortcut and QuickLaunch behaves always strange: Afaik they are starting the programs without any environmental variables, at least that was the case some years ago. I think there is even a bugticket somewhere.

Create a small program which dumps the env vars into a file and run it from tracker, shortcuts and quick launch, then compare the results.

1 Like

Hi,
Don’t forget to submit your work at Gerrit (review.haiku-os.org) so it can be merged!

2 Likes

One of the more annoying things… the ticket is #12534.

2 Likes

I’ve got a little bit of cleanup on the Terminal argument left, I’ll be submitting it soon.

I can envision a picker in addition to the textbox. That textbox is important because it’s your access to the shell. Now if only I could figure out Jeremy’s code. I always found his code to be beautiful, yet of his own quirky idiom. /me reminisces about BeShare. 8^)

I look forward to working with his SpicyKeys code in Shorcuts.

Finally got the patch for Terminal submitted to gerrit for review. I look forward to comments and criticism.

To offer a different perspective, it’s pretty ridiculous Terminal doesn’t have this option already. I ended up invoking Tracker add-on in Koder to support opening Terminal in a specific directory, after seeing all the magic the add-on does in order to do that.

2 Likes

I don’t see it as overly ridiculous. We’re a growing project. The feature isn’t totally essential to use Terminal. It’s just a nice thing to have. Patch is submitted, pending review as we speak. It may be small, but I’m rather proud of it. Terminal -w marks my first ever code contribution to any project. If it weren’t for low hanging fruit like this, new devs like me would be lost in a sea of difficult tasks above our pay grade. @waddlesplash’s, and others comments pointed me to another area of interest for me to look into fixing. SpicyKeys was one of my must haves back when BeOS R5 was still a thing. Now that my C++ coding skills are progressing past the tutorial stage, I’m a bit better equipped to do something about it now.

2 Likes