I am using Gnome 2's gnome-terminal, this gives me easy open/close/change in terminal sessions: ctrl+shift+t open a new terminal; "[ctrl+c] ctrl+d" closes it; alt+[N] changes to other sessions, keeping the current one open.
The relevant parts of my .bashrc, .bash_login and .bash_logout are:
.bashrc:
Code:
# many parts removed, this MAY not work as is for the missing parts => point it
# I am not sure what this line do, but it is there:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
export HISTCONTROL=ignoreboth:erasedups
export HISTSIZE=10000
export HISTFILESIZE=10000
# append to the history file, don't overwrite it
shopt -s histappend
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# Apaga linhas do histórico, aceitando mais de um argumento de uma vez
function histd()
{
if (( $# < 1)); then
echo 'Use assim: histd 15 14 13 12 [...]'
echo -e "\tcom os números em ordem DECRESCENTE - ou não funciona"
return
fi
ult=$1
echo "history -d $1"
teste=!$1
echo "'$teste' devia funcionar... sqn"
history -d $1
while ((1)); do
shift
if (( $# == 0 )); then
break;
fi
if (( $ult < $1 )); then
echo 'Sou bonzinho, mas me ajude. Desse jeito dá errado!!'
echo 'Use assim: histd 15 14 13 12'
echo -e "\t Com TODOS os números em ordem DECRESCENTE!"
return
fi
echo "history -d $1"
ult=$1
history -d $1
done;
}
# rmhist <primeira-linha-apagada> <última-apagada>
# -> Line numbers according to the output of history.
# -> Use history -w to force a write to the history file.
function rmhist()
{
if (( $# < 1)); then
echo 'rmhist <1a-linha-apagada> <última-linha-apagada>'
echo -e '\tOu...'
echo 'rmhist <quant-de-últimas-linhas-apagadas>'
return
fi
if (( $# == 1 )); then
comeco=$(( $HISTCMD-1 ))
if (( $1 > 10 )); then return; fi
if (( $1 < 0 )); then return; fi
fim=$(( $HISTCMD-$1 ))
for (( i=$comeco; i>=$fim; i--)); do
echo -n $i,
history -d $i
done;
echo
elif (( $# == 2)); then
for (( i=$2-$1; i>=0; i--)); do
history -d $1
done
fi
}
# vim: fileencoding=utf-8
.bash_logout (all of it)
Code:
# ~/.bash_logout: executed by bash(1) when login shell exits.
# when leaving the console clear the screen to increase privacy
if [ "$SHLVL" = 1 ]; then
[ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
.bash_login does not exist
I am doing this having some terminal sessions opened, and I will not close them to make these tests. I will make a few steps to make is safe against some corruptions, if they are wrong or are potentially not enough, please say!
I assume that you are using ignoreboth to ignore commands with spaces before them => we can type commands that will not affect the history of any session.
All comments that start with #N should be made in the session number N. #1 => in session 1 and so on. Other comments are just to show other actions, like openning and closing sessions (with a ctrl+d, not with the exit command).
Some commands are intentionally started with spaces. Steps to have duplicate lines in history:
Code:
# make a backup, in any session, of the current history.
cp ~/.bash_history ~/.bash_history__beforeTests.2016.09.07 #save everything as is
# open session 1
history -c #1
history -w #1
history #1 should show only these 2 last lines
# open session 2
history #2 note the space. Will show only the -w line
aaaa #2
bbbb #2
cccc #2
dddd #2
# close session 2
# open session 3
history #3
# Should be:
# 1 history -w
# 2 aaaa
# 3 bbbb
# 4 cccc
# 5 dddd
# open session 4
bbbb #4
history #4
# Should be:
# 1 history -w
# 2 aaaa
# 3 cccc
# 4 dddd
# 5 bbbb
# close session 4
# close session 3
# open session 5
history #5
# Should be:
# 1 history -w
# 2 aaaa
# 3 bbbb
# 4 cccc
# 5 dddd
# 6 bbbb
# note history entries 3 and 6: both should not exist!
# close all these sessions
# now, in any other session, reset the history to what it
# was before the tests were made
cp ~/.bash_history__beforeTests.2016.09.07 ~/.bash_history
I have not tried other tests now, but I have repeated this one (to test it worked). It may not be the only way to get duplicates inserted in the history.
Now I hope that my restored backup is still there the next time I reboot my computer.