It would be nice to have a shortcut that opens a new session in the same $PWD as the current one.
Unfortunately it's not possible to retrieve the $PWD from the Konsole KPart component that Yakuake embeds, so I can't get at the data needed to spawn another at the same location. A wish along those lines needs to be filed against Konsole: I'm reappropriating this one for the purpose. Renamin & reassigning.
It is possible. I've just written a patch. I'll upload it to gitorious or github in a minute and post a link here (usually I like hg more but it failed to clone the svn repo for some reason). :) The API to retrieve the PWD is this: http://api.kde.org/4.x-api/kdelibs-apidocs/interfaces/html/classTerminalInterfaceV2.html Well, this way you get the PID of the terminal. You can get the PWD by reading /proc/$PID/cwd (like konsole does it already!). Well yes, this is Linux only. But better than nothing. Maybe one can do something similar under BSD. I guess Yakuake is not used on other OSes.
Here is the git repo: http://github.com/panzi/Yakuake
Created attachment 38333 [details] This patch makes a new session use the same $PWD as the current session Currently this feature is not optional. When I have time I might make it optional, so that there is in fact a additional shortcut for "open new session in same $PWD".
PS: (Off Topic) I've seen that you often use code like this: if (!m_terminals.contains(terminalId)) return; Terminal* terminal = m_terminals.value(terminalId); This makes two hastable lookups. Ok, this is really not performance critical, but I think this would still be much more nice: Terminal* terminal = m_terminals.value(terminalId); if (!terminal) return; See: http://doc.trolltech.com/4.5/qhash.html#value http://doc.trolltech.com/4.5/containers.html#default-constructed-values
Right, I forgot about the TerminalInterfaceV2 additions for Dolphin :). However: There's also the fact that Konsole profiles already have a "Start in same directory as current tab" checkbox, which however is non-functional for the KPart -- imho it'd be better to fix this in Konsole, which also takes care of the "making it optional" part. And for a shortcut, I still think engineering-wise there should be an API in the KPart to avoid the code duplication between Konsole and Yakuake, e.g. so that when a BSD solution is found it can be added in one place rather than two. I'm not very fond of hacks. Regarding your point in commant #5, you're right in principle. I use contains() out of habit (and consciously) because value() returns a default-constructed value for a non-existing key, which can bite you in the ass in some situations. It doesn't matter for a pointer type, as you rightly point out - a default-constructed one is 0 - but I generally find it more useful to foster cautious habits than micro-optimize. However as with any programmer the efficiency loss has been nagging me too, and now that someone else has noticed I might feel forced to change it ;).
Btw, to take things further: I also want to eventually have an API in the Konsole KPart that allows listing available profiles and spawning a KPart with a particular profile. Yakuake's New Session menu (click and hold the "New Tab" button) could then list the available profiles, and there could also be a facility to assign shortcuts to profiles (the current entries of the New Session menu are already KActions in the action collection, i.e. found in Configure Shortcuts). Your shortcut could then be realized by way of spawning a tab/terminal with a profile that has the "Start in same directory as current tab" checked (once it's fixed anyway).
*** Bug 227656 has been marked as a duplicate of this bug. ***
*** This bug has been confirmed by popular vote. ***
*** Bug 169058 has been marked as a duplicate of this bug. ***
If #156919 is implemented, does that make this problem solvable(at least for yakuake)?
It'd be inefficient, but solvable, yeah.
Git commit a7f71fe903df30b9aaa27f02df35d0eef92fb597 by Jekyll Wu. Committed on 22/03/2012 at 08:55. Pushed by jekyllwu into branch 'master'. Add slot currentWorkingDirectory() for getting the current wokring directory REVIEW:104362 CCMAIL: hein@kde.org M +7 -0 src/Part.cpp M +7 -0 src/Part.h http://commits.kde.org/konsole/a7f71fe903df30b9aaa27f02df35d0eef92fb597
*** Bug 297222 has been marked as a duplicate of this bug. ***
*** Bug 321834 has been marked as a duplicate of this bug. ***
And what is the situation with this bug for now? I'm using archlinux with yakuake 2.9.9-1 and this option doesn't work
This is kind of fixed but seems to only work if the current tab isn't running anything in the foreground. Otherwise a new tab lands me in my home directory. Quite tedious as often I want a few tabs in the current directory for doing different things. For example I like evince and gedit to have it's own tab because they write a continuous stream of stupid warnings.
Well, my patch still works: https://github.com/panzi/Yakuake/commit/e5668b2ce4d142070631374306667f3e3a3d8369 And it does also work when an application (e.g. rails server) is running in the current tab. (I'm on KDE 4.11.5)
Still not working on Archlinux's Yakuake 2.9.9-3 and yakuake-git :( Is there any issue left with Mathias' patch?
Is there some news?
I'm on Ubuntu 14.04.2 using KDE 4.13.3. I have the checkbox set for opening in same directory in my profile. It doesn't work. In Yakuake, I always land back in my home directory…
Bug is still present on Arch, running Yakuake Version 2.9.9 Konsole remembers the current PWD just fine though, as does gnome-terminal, xfce4-terminal, guake, ... Maybe somebody could give us an update on this 6 year old bug? Regards
On a side note, have you guys thought about replacing whatever konsole is doing now (digging under /proc) with what gnome-terminal and other vte derivatives, macOS's Terminal.app and perhaps iTerm2 do, namely using the OSC 7 escape sequence by the shell to explicitly tell the current working directory to the terminal? I'm not aware of the API and whether this change would have any implications there, but... > This is kind of fixed but seems to only work if the current tab isn't running > anything in the foreground. Otherwise a new tab lands me in my home directory. ... I guess it would (among others) have the benefit that these kinds of problems could no longer occur.
OSC 7 supoort was committed over a year ago - I'd have to check how the KPart handles it. I assume from the recent reports, it is not working as people expects it to.
Haha, cool... sorry I've missed out on this :)
Good to see some new comments. I really like Yakuake but this bug drives me crazy. Any one know if Mathias' patch still works?
I updated Yakuake for the first time in a long while and rebased my patch on top of master: Now it seems to be buggy for the first time you try to open a new tab in the same directory for some reason. Didn't had that behavior before. Konsole doesn't behave that way.
Created attachment 107784 [details] Rebased patch to master
I applied your patch, it's working on my end. Just to be clear, the patch remembers the $PWD in the current session (e.g., when splitting terminals horizontally/vertically), but not for new sessions (e.g., opening a new tab with ctrl+shift+t). I'm not sure if that's the desired behavior, I'd prefer it to always remember the $PWD, but it's still a lot better than before. Thanks Mathias! Regards, Walter
What do you mean by remembers? Also personally I only use tabs, not splitting sessions. The buggy behavior it has now annoys me. How did that happen? :/
By "remembers" I means that it opens the terminal at the same $PWD as the last selected terminal. For me, when I open a new terminal in a new tab by pressing ctrl+shift+t, the terminal opens in ~ every time, so the patch doesn't seem to work. When I open a new terminal in a split, e.g., ctrl+( or ctrl+) or right-clicking, the new terminal opens in the same $PWD as the previously selected terminal. So it doesn't seem to work for me as it does for you, but it's still better than what I had. I might mention that I'm running Yakuake in XFCE in Arch, not in KDE, maybe that has something to do with it? I'll try again tomorrow with a clean config too. Regards
For me it opens the new tab in the $PWD the current tab had _before the last command_. That means if you e.g. do `cd ~/images` and then open a new tab it will open in ~. But if you just do an extra enter after the cd the new tab WILL be in ~/images. Weird. It wasn't like that before I updated (before I rebased to current master).
Created attachment 107788 [details] Don't use TerminalInterface::currentWorkingDirectory() under Linux Workaround for erratic TerminalInterface::currentWorkingDirectory() behavior by reading /proc/$PID/cwd directly (which is Linux-only).
Comment on attachment 107788 [details] Don't use TerminalInterface::currentWorkingDirectory() under Linux This only changes Terminal::currentWorkingDirectory() and doesn't the the rest of my patch. I use this personally because the erratic behavior was too annoying for me.
I see that this bug was originally set to yakuake and then moved to Konsole. Since these patches are for yakuake, I would suggest either moving this back over to yakuake or creating a new bug report (which might be cleaner ATM).
Matías, I updated git and applied your second patch, nothing changed on my side, behavior is the same. To check if it had something to do with my environment (XFCE, .bashrc, yakuakerc), I installed plasma-desktop and created a new user. Exactly the same behavior as before, the $PWD is properly set for split terminals, but not for new tabs. It's still an improvement for me :) As I side-note, with split terminals I don't remember seeing the issue you noticed where you need to hit enter after changing directories.
Do you use the shortcut for "New Session (Same Working Directory)"? Because my patch does not change the "New Session" shortcut, but instead adds a new shortcut. This way you can have both behaviors with different shortcuts.
You're right, I forgot to set the new shortcut! I think what got me is that your patch made it work for split terminals without any new shortcuts. Works perfectly now in all cases. Any chance of getting the patch into Yakuake?
Reassigning (back) to yakuake developers. See comment #35 and comment #38.
Since there seems not to be any activity for 4 years I would like to help other users who stumble upon this bug with a dirty fix by Michael Wiebusch which works for me on Ubuntu 20.04. I found it on his blog from 2016 here: https://acidbourbon.wordpress.com/2016/12/03/a-quick-and-dirty-fix-for-yakuakes-open-new-tab-in-same-directory-issue/. From the blog: ---------------- You simply append the following code to your /home/$USER/.bashrc ``` if [ $(basename "/"$(ps -f -p $(cat /proc/$(echo $$)/stat | cut -d \ -f 4) | tail -1 | sed 's/^.* //')) == "yakuake" ]; then # go to last active cwd if [ -e /dev/shm/$USER-yakuake-cwd ]; then cd "$(cat /dev/shm/$USER-yakuake-cwd)" fi # on each stroke of the return key, save cwd in a shared memory export PS1=$PS1'$(pwd > /dev/shm/$USER-yakuake-cwd)' fi ```
yakuake 20.12.3 opens new tabs in the same directories of the old one. Is this bug still valid?
Maybe I'm too rash to be the one to mark this resolved, but I'm doing it. For years, I never had Yakuake keep the directory in new sessions. But it works now. Something clearly changed that fixed this. I think if anyone has further issues, it should be a new bug.