You know what I hate? My history isn't aggregated in real time across all my Mac OS X terminal windows.
You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Especially when I hit the up arrow to go back in my terminal history.
history -a # append history lines from this session to the history file.
#History file may contain history from other terminals not in this one so:
history -c # clear [in-memory] history list deleting all of the entries.
history -r # read the history file and append the contents to the history list instead.
I've heard that -n can be problematic which is why -c then -r is used.
> You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly.
Yeah, keeping ctrl pressed in and pressing x followed by e (CTRL + x e) will open up the current line in $EDITOR and when you edit and save, replaces the current line with what you entered in your editor. Really a killer feature.
In Linux with bash (and probably other shells that are bash-compatible), you can use vi to edit any of the commands in your command history, and then execute the edited version.
Do this at the command prompt, or once in your ~/.bash_profile to make it permanent:
set -o vi
After that, you can search for any of the commands in your history, edit it, and then execute the edited command, by doing this:
At the prompt, type Esc once to get into vi command mode. Then you can press the k key repeatedly to scroll up through the command history, or (often easier) use the ? (search backward) vi command to search for a pattern to find a specific command. Once found, press v to edit it in a temp file. Then when you save and quit, the edited command gets executed.
The same technique works with emacs as the editor instead of vi, if you don't give the 'set -o vi' command, because the default editor for command line history is emacs. Also, if you have run 'set -o vi', you can switch the editor for commands back to emacs with 'set -o emacs'.
The 'set -o <editor>' bit sets the readline editing environment to be similar to vi. It can be set to emacs.
C-xC-e (edit-and-execute-command) invokes the editor specified by $VISUAL, $EDITOR, or emacs, in that order. You could set it to scrivner if you wanted to (though I'm not sure that would necessarily work on exit).
I've tested with VISUAL set to nedit, from which I then changed it to uptime. Now I get loadavg when I want to edit my command line ;-)
Yes, that is also a solution. However, you cannot use vim so if you're used to vim, it might feel limited without certain commands. You're also missing eventual plugins.
function fancyPrompt {
local bgBlue="\[\033[48;5;31m\]"
local fgBlue="\[\033[38;5;31m\]"
local fgWhite="\[\033[38;5;231m\]"
local bgDarkBlue="\[\033[48;5;24m\]"
local fgDarkBlue="\[\033[38;5;24m\]"
local bgDarkGray="\[\033[48;5;237m\]"
local bgLightGray="\[\033[48;5;245m\]"
local fgLightGray="\[\033[38;5;245m\]"
local colorClear="\[\033[0m"
local branch
local branch_symbol="\[\] "
if branch=$( { git symbolic-ref --quiet HEAD || git rev-parse --short HEAD; } 2>/dev/null ); then
branch=${branch##*/}
export PS1="${bgBlue}${fgWhite}\h${colorClear}${fgBlue}${bgDarkBlue}\[\] ${fgWhite}\w${bgLightGray}${fgDarkBlue}\[\] ${fgWhite}${branch_symbol}${branch}${fgLightGray}${bgDarkGray}\[\] ${colorClear}"
else
export PS1="${bgBlue}${fgWhite}\h${colorClear}${fgBlue}${bgDarkBlue}\[\] ${fgWhite}\w${bgDarkGray}${fgDarkBlue}\[\] ${colorClear}"
fi
}
That's quite pretty. How do you get the triangles?
I've been loving a prompt which color codes git branches (which, if I understand right, would be built-in if I used zsh instead of bash) [0], though I have to edit the last line in order to get my history appendation working as well.
> Typing in long commands in the Mac OS X terminal and then them wrapping weirdly.
For all people who dont use Mac OS X:
This happens because your PS1 is wrongly set and bash cant calculate correctly the length left of your line. Try it out, by going back to default with no colors and crap and see how long it goes.
For mac os x users. The above wont help, dont even try it.
I prefer to keep mine separate, but I always use specific terminals / screen sessions for (mostly) the same type of work (admin, specific projects, web dev, etc.) so each have their own history, as well as keeping a per-directory record.
So far over 130000 command lines (with timestamp & cwd) for past 2.5 years, just on my laptop.
You know what I hate? My history isn't aggregated in real time across all my Mac OS X terminal windows.
I used to feel this way. Then one day I figured out how to enable this in Bash. Resulted in a confusing mess. Turns out you most likely want terminal sessions to be distinct until you end them.
You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Especially when I hit the up arrow to go back in my terminal history.