This forum has been archived. All content is frozen. Please use KDE Discuss instead.

omit the "cd" entry in ~/.bash_history when I open terminal

Tags: None
(comma "," separated)
User avatar
oracle2b
Registered Member
Posts
78
Karma
0
OS
I regularly make use of the HISTCONTROL="ignorespace" to omit entires on my bash history. When I open up a terminal in dolphin the "cd /directory" appears in ~/bash_history. My history is cluttered wit these entries and I'd like to completely omit any entry beginning with "cd" from writing to bash_history. How can I go about doing this?


Edit:

FIXED in KDE 4.9 by Frank Reininghaus

Last edited by oracle2b on Thu Sep 06, 2012 9:15 pm, edited 1 time in total.


All answers are all replies, but not all replies are answers.
User avatar
google01103
Manager
Posts
6668
Karma
25
from http://www.thegeekstuff.com/2008/08/15- ... /#more-130

15. Ignore specific commands from the history using HISTIGNORE

Sometimes you may not want to clutter your history with basic commands such as pwd and ls. Use HISTIGNORE to specify all the commands that you want to ignore from the history. Please note that adding ls to the HISTIGNORE ignores only ls and not ls -l. So, you have to provide the exact command that you would like to ignore from the history.
# export HISTIGNORE="pwd:ls:ls -ltr:"
# pwd
# ls
# ls -ltr
# service httpd stop

# history | tail -3
79 export HISTIGNORE="pwd:ls:ls -ltr:"
80 service httpd stop
81 history
[Note that history did not record pwd, ls and ls -ltr]


OpenSuse Leap 42.1 x64, Plasma 5.x

User avatar
oracle2b
Registered Member
Posts
78
Karma
0
OS
I tried using

# export HISTIGNORE="cd *"

and

# export HISTIGNORE="cd /*"

but that didn't work.


All answers are all replies, but not all replies are answers.
User avatar
google01103
Manager
Posts
6668
Karma
25
either HISTIGNORE does not allow wild cards, uses a different syntax or there is another option needed to enable them - no idea

2 thoughts:
1) if the number of folders cd'ed to is limited list them explicitly in HISTIGNORE
2) alias history to alias history='history|grep -v cd', of course you'd want to do something a bit more complex using regexp and checking that the first 3 non-blank chars are = 'cd '


OpenSuse Leap 42.1 x64, Plasma 5.x

freininghaus
Moderator
Posts
224
Karma
1
OS
AFAIK, commands are not added to the history if they are prepended with one or more spaces. Maybe we should just send the "cd" command with a space prepended in TerminalPanel::sendCdToTerminal(const QString&). That would resolve this issue without any action required on the user side.
freininghaus
Moderator
Posts
224
Karma
1
OS
freininghaus wrote:commands are not added to the history if they are prepended with one or more spaces.

Hm, it seems that this is only true for bash. I've tried zsh and sh, and these also commands with a prepended space to the history. But they execute the command correctly, so it seems that adding the space would at least not cause any trouble for non-bash users.
User avatar
google01103
Manager
Posts
6668
Karma
25
freininghaus - in zsh you'd need to enable the option and for bash you'll need to ensure that the option is enabled (for me it was)

for zsh http://zsh.sourceforge.net/Doc/Release/Options.html
HIST_IGNORE_SPACE (-g)
Remove command lines from the history list when the first character on the line is a space, or when one of the expanded aliases contains a leading space. Only normal aliases (not global or suffix aliases) have this behaviour. Note that the command lingers in the internal history until the next command is entered before it vanishes, allowing you to briefly reuse or edit the line. If you want to make it vanish right away without entering another command, type a space and press return.


also there is the case that the user wishes cd to be included in history so a config option should be available


OpenSuse Leap 42.1 x64, Plasma 5.x

freininghaus
Moderator
Posts
224
Karma
1
OS
google01103: Thanks for the info!

Unfortunately, enabling options based on which shell the user uses seems to be pretty difficult to me. At the moment, we just create the terminal using the KonsolePart factory. Konsole does all the work for us.

I'm not sure if the config option is a good idea. I think that one should try to keep the number of options low and only add an option if there really is a large group of users who are not happy with the default.

So I would say that we should either leave it as it is or add a hardcoded space, but I'l discuss this with Peter.
User avatar
google01103
Manager
Posts
6668
Karma
25
freininghaus wrote:<snip>Unfortunately, enabling options based on which shell the user uses seems to be pretty difficult to me. At the moment, we just create the terminal using the KonsolePart factory. Konsole does all the work for us.<snip>

this appears to be the most accurate as the shell being run is not necessarily your default shell
Code: Select all
echo $0
this works because the program being run is the shell


OpenSuse Leap 42.1 x64, Plasma 5.x

freininghaus
Moderator
Posts
224
Karma
1
OS
google01103 wrote:this appears to be the most accurate as the shell being run is not necessarily your default shell
Code: Select all
echo $0
this works because the program being run is the shell

We could send that command to the shell inside the Terminal Panel, but AFAIK there's no way to read out the result from Dolphin. Even if we could find out the shell being run using your suggestion, it's still far from trivial to adjust the shell's settings appropriately. We would need a lot of complex and bug-prone code for that.

I've started a discussion on the mailing list about this isse: http://lists.kde.org/?t=133844952400003&r=1&w=2. It looks like we'll add a hardcoded space to the commands sent to the terminal.
User avatar
oracle2b
Registered Member
Posts
78
Karma
0
OS
I've started a discussion on the mailing list about this isse: http://lists.kde.org/?t=133844952400003&r=1&w=2. It looks like we'll add a hardcoded space to the commands sent to the terminal.



I'd just like to thank everyone in this thread for helping to solve this issue and making my request a staple in future KDE releases.


All answers are all replies, but not all replies are answers.
Mailaender
Registered Member
Posts
20
Karma
0
OS
I think this problem is back. I am on KDE 22.04.3 and Dolphin, Kate spam the terminal with cd commands which I don't know how to ignore.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]