Konsole/Bash template possible?

I like that my commands are saved to be reused at a later time, but a lot of “one-time” commands or experiments bloat my bash history. So for the moment I go and delete in the history file the not needed commands… that works but is somehow annoying.

Is there a possibility to make an template with my most used commands, so that I simply can delete regular delete the bash history?

If possible, I could even save a command, to delete the history file.

greetings,
Daniel

If you put a space in front of a command it will not save in history (at least in zsh).

setopt HIST_IGNORE_SPACE
1 Like

For personal commands. You can make a .personal_aliases file and source it in your .bashrc or .zshrc with your personal commands.

In your .bashrc and/or .zshrc source ~/.personal_aliases

1 Like

When I was using bash, I used a command that helped browsing my history :

cat ~/.bash_history| fzf | sh

I had an alias for this in my .bashrc, fzf package needs to be installed.

but an alias is not selectable with the arrows from the keyboard. Them are “only” shortcuts.

endeavourOS use Bash, I’m ok with it, but on manjaro I had zsh wich was a lot greater. are there downsides to use zsh? Perhaps that already improve my situation.

When yes, is there a good tutorial to switch from bash to zsh?

My alias looked liked this :

alias hist='cat ~/.bash_history| fzf | sh'

I had to type hist+Enter, then the beginning of the command, fzf doing the search in the history.
With zsh, I use a plugin that do the same, I just need to type Ctrl+r.

When you switch to zsh, the first time a configuration tool is launched, it helps to configure zshrc.
zsh-completions, zsh-autosuggestions and zsh-syntax-highlighting packages are necessary (at least to me :slightly_smiling_face: )
After this, you can search for prompt themes and plugins managers.

edit: this page helps a lot
https://wiki.archlinux.org/title/Zsh

This one too :

1 Like

Change to zsh or visa versa.
To get a list of the paths.

$ chsh -l

You can use to set (-s) zsh or bash.
As normal user.

$ chsh -s /bin/zsh

Logout and in again.

1 Like

If you don’t want a command saved to history, just add a space in front of it.

EDIT: I’m too slow… :turtle:

Also have a look at:

Examples · junegunn/fzf Wiki · GitHub

There is some good stuff for bash & zsh there.

1 Like

History helper : https://github.com/dvorka/hstr .

2 Likes

hstr looks promising, I will give it a try, thx

One thing that might be useful is to erase history duplicates:

# File ~/.bashrc:
export HISTCONTROL="erasedups"
3 Likes

@manuel thanks for that tip, this helps a lot

1 Like

If you are using zsh these are the settings I use to deal with globbing and history

## Options section
setopt correct                                                  # Auto correct mistakes
setopt extendedglob                                             # Extended globbing. Allows using regular expressions with *
# setopt nocaseglob                                               # Case insensitive globbing
setopt rcexpandparam                                            # Array expension with parameters
setopt nocheckjobs                                              # Don't warn about running processes when exiting
setopt numericglobsort                                          # Sort filenames numerically when it makes sense
setopt nobeep                                                   # No beep
setopt appendhistory                                            # Immediately append history instead of overwriting
setopt share_history
setopt histignorealldups                                        # If a new command is a duplicate, remove the older one
setopt autocd                                                   # if only directory path is entered, cd there.
setopt auto_pushd
setopt pushd_ignore_dups
setopt pushdminus
# setopt completealiases