Both sides previous revision
Previous revision
|
Next revision
Both sides next revision
|
it-tricks [2017/10/16 17:58] popel moved to [[:grid]] |
it-tricks [2017/10/16 18:12] popel [Bash] |
* Use Bash auto-completion (''source /etc/bash_completion''). Some tools have plugins, e.g. many [[https://metacpan.org/pod/Bash::Completion|Perl tools]]. | * Use Bash auto-completion (''source /etc/bash_completion''). Some tools have plugins, e.g. many [[https://metacpan.org/pod/Bash::Completion|Perl tools]]. |
* ''export HISTCONTROL=ignoreboth'' results in bash history ignoring duplicate entries and entries starting with a space. | * ''export HISTCONTROL=ignoreboth'' results in bash history ignoring duplicate entries and entries starting with a space. |
* See ''/ha/home/bojar/diplomka/granty/cracker-2015/mtm-2016-organization/accounts-mtm16/bash-profile-for-ufal-accounts'' for: | |
* bash history local in the current directory | ==== Directory-local Bash history ==== |
| * Ondřej Bojar prefers to store the history in each directory in ''.history-bojar''. See ''/home/bojar/diplomka/granty/cracker-2015/mtm-2016-organization/accounts-mtm16/bash-profile-for-ufal-accounts'' |
| * Note that this creates the ".history-your-name" wherever you have write access and some ÚFALers are not happy with this. In addition everyone sees what you did (this may be useful, but be careful). |
| * Ondřej Dušek (''/home/odusek/.bashrc'') uses a variant more friendly to others, which saves the histories in his home (but does not handle renamed directories):<code> |
| if [ -z "$USER" ]; then |
| export USER=`whoami` |
| fi |
| |
| # Store all history with times and directories |
| function store_history () { |
| history 1 | awk '($2 !~ "^[mr]?cd[0-9a-z]?$") {$1="_T="strftime("%Y%m%d_%H:%M:%S_") PROCINFO["ppid"] "_PWD=" ENVIRON["PWD"] "\t"; $2=gensub("^_T=[-_0-9:]*[ \t]* *", "", 1, $2); $2=gensub("^_P=[^ \t]* *", "", 1, $2); print;}' >> ~/.history-all-$USER |
| } |
| export PROMPT_COMMAND="store_history" |
| |
| # Grep history |
| function dhist (){ |
| DIR=`pwd` |
| command grep "_PWD=$DIR"$'\t'".*$@" ~/.history-all-$USER | tail -n 30 |
| } |
| |
| function hist (){ |
| if [ "$#" -eq 0 ]; then |
| tail -n 30 ~/.history-all-$USER |
| else |
| command grep "$@" ~/.history-all-$USER | tail -n 30 |
| fi |
| } |
| </code> |
===== Git ===== | ===== Git ===== |
* [[https://github.com/magicmonty/bash-git-prompt|bash-git-prompt]] shows e.g. the current branch and status. Martin Popel prefers to configure it (in bashrc) with | * [[https://github.com/magicmonty/bash-git-prompt|bash-git-prompt]] shows e.g. the current branch and status. Martin Popel prefers to configure it (in bashrc) with |