5 ms·
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
by curiousHacker 12y ago
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.
- ibotty 12y ago> My history isn't aggregated in real time across all my Mac OS X terminal windows. zsh has `setopt inc_append_history` and `setopt share_history`. i am sure bash has something similar.
- Tiksi 12y agoHere you go, just throw it in your .bashrc: shopt -s histappend export HISTSIZE=100000 export HISTFILESIZE=100000 export HISTCONTROL=ignoredups:erasedups export PROMPT_COMMAND="history -a;history -c;history -r;$PROMPT_COMMAND" I wish I could give credit to where I originally found this but it was ages ago.
- mtford 12y agoMany thanks for this! This has been a thorn in my side for a while but never got round to doing anything about it...
- grimgrin 12y agoDon't you want HISTCONTROL=ignoreboth ?
- gknoy 12y agoI've been using `history -a`, but what do `history -c` and `history -r` do? It looks like it clears your shell's history, and then re-populates it from the .bash_history file?
- Flenser 12y agohistory -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.
- JoeAcchino 12y ago> You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. I solved this by adding the following line in my ~/.bashrc shopt -s checkwinsize Never tried on Mac OS X though, so I don't know if it works.
- diggan 12y ago> 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.
- vram22 12y agoIn 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'.
- diggan 12y agoYes, 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. It's better than nothing though.
- ejstronge 12y agoI don't think this is the case, though I may be misunderstanding what you wrote. At the shell, it's true that you're limited to vi-style controls (so no text objects like ci"). However, once you press 'v' in normal mode you can drop into either vi or vim - this only depends on what $EDITOR is set to[1]. [1] http://blog.sanctum.geek.nz/vi-mode-in-bash/ http://blog.sanctum.geek.nz/vi-mode-in-bash/
- Spiritus 12y ago>You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Are you escaping your color codes in PS1 correctly? Bad: PS1="\033[1;32m \w \033[m $" Good (notice the extra \[ and \]): PS1="\[\033[1;32m\] \w \[\033[m\] $"
- raju 12y agoThis. Right Here. For the longest time I could not figure out why my Ctrl-r (history) was so messed up.
- tambourine_man 12y agoMine seems escaped as hell, but still gets wrapped. Anything I'm missing? edit: couldn't get UTF-8 branch symbol to be properly displayed here, but this is how it looks: http://i.imgur.com/zuq24gV.png?1 http://i.imgur.com/zuq24gV.png?1 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 }
- gknoy 12y agoThat'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. 0: https://gist.github.com/tobiassjosten/828432 https://gist.github.com/tobiassjosten/828432
- antocv 12y ago> 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.
- mitchty 12y agoI found the solution to bash problems was to move to zsh. I did that almost 10 years ago and haven't regretted the decision.
- jdong 12y agoYou should just move to zsh that does this natively and in a clean manner.
- naner 12y agoYou 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.
- toddkaufmann 12y agoI 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.