Answers:
如果对bash和zsh使用默认值:
$ cat ~/.histfile >> ~/.bash_history
$ youreditor ~/.zshrc
# Here change your config to:
HISTFILE=~/.bash_history
$ rm ~/.histfile
现在,两个外壳中都具有相同的历史记录文件。
: 1399608924:0;hg diff
而我的.bash_history有简单的行hg diff
。也许是因为我正在使用oh-my-zsh?
unsetopt EXTENDED_HISTORY
获取与bash兼容的仅命令历史记录。
不完全是您要查找的内容,但是为了从bash导入到zsh,可以使用以下node.js脚本:
// This is how I used it:
// $ node bash-history-to-zsh-history.js >> ~/.zsh_history
var fs = require("fs");
var a = fs.readFileSync(".bash_history");
var time = Date.now();
a.toString().split("\n").forEach(function(line){
console.log(": "+ (time++) + ":0;"+line);
});
作为对Elad的回应,人们可能拥有.bash_history文件,这些文件在每个以(#)开头的命令前都有多余的一行,并在(123456789)之后有尾随数字,例如:#123456789。如果您的bash_history文件包含这些额外的行,请使用Elad的代码的此修改版本来处理要使用的纯zsh格式的历史记录。感谢Elad的快速转换代码。
/*
* You should backup your .bash_history file first doing this:
* $ cp ~/.bash_history ~/.bash_history.backup
*
* create the .js file to use first:
* $ touch ~/.bash-history-to-zsh-history.js
*
* This is how I use it based on Elads example:
* $ node ~/.bash-history-to-zsh-history.js >> ~/.zsh_history
*
**/
var fs = require("fs");
var a = fs.readFileSync(".bash_history");
var time = Date.now();
a.toString().split("\n").forEach(function(line){
if (line.indexOf("#")!=0) console.log(": "+ (time++) + ":0;"+line);
});