Я использую подход, обозначенный here
В основном, он использует python и sets
для обработки уникального списка всех команд, введенных во все ваши оболочки. Результат сохраняется в .my_history
. Используя этот подход, все команды, введенные в каждую открытую оболочку, сразу доступны во всех других оболочках. Каждый cd
хранится, поэтому файл иногда требует ручной очистки, но я считаю, что этот подход лучше подходит для моих нужд.
Необходимые обновления ниже.
.profile:
# 5000 unique bash history lines that are shared between
# sessions on every command. Happy ctrl-r!!
shopt -s histappend
# Well the python code only does 5000 lines
export HISTSIZE=10000
export HISTFILESIZE=10000
export PROMPT_COMMAND="history -a; unique_history.py; history -r; $PROMPT_COMMAND"
* unique_history.py *
#!/usr/bin/python
import os
import fcntl
import shutil
import sys
file_ = os.path.expanduser('~/.my_history')
f = open(file_, 'r')
lines = list(f.readlines())
f.close()
myset = set(lines)
file_bash = os.path.expanduser('~/.bash_history')
f = open(file_bash, 'r')
lines += list(f.readlines())
f.close()
lineset = set(lines)
diff = lineset - myset
if len(diff) == 0:
sys.exit(0)
sys.stdout.write("+")
newlist = []
lines.reverse()
count = 0
for line in lines:
if count > 5000:
break
if line in lineset:
count += 1
newlist.append(line)
lineset.remove(line)
f = open(file_, 'w')
fcntl.flock(f.fileno(), fcntl.LOCK_EX)
newlist.reverse()
for line in newlist:
f.write(line)
fcntl.flock(f.fileno(), fcntl.LOCK_UN)
f.close()
shutil.copyfile(file_, file_bash)
sys.exit(0)
взглянуть на переменную HISTCONTROL среды. Также сделайте 'shopt | grep hist' и google. На моем ubuntu (12.04) он работает как ожидалось – hek2mgl
См. Http://unix.stackexchange.com/q/1288/9454 –