Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
meishi125478
ohmyzsh
提交
523b26c6
O
ohmyzsh
项目概览
meishi125478
/
ohmyzsh
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
ohmyzsh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
523b26c6
编写于
9月 23, 2012
作者:
R
Robby Russell
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1321 from jimhester/per-directory-history
Per directory history plugin
上级
5f16ede7
cc831508
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
148 addition
and
0 deletion
+148
-0
plugins/per-directory-history/per-directory-history.plugin.zsh
...ns/per-directory-history/per-directory-history.plugin.zsh
+148
-0
未找到文件。
plugins/per-directory-history/per-directory-history.plugin.zsh
0 → 100644
浏览文件 @
523b26c6
#!/usr/bin/env zsh
#
# This is a implementation of per directory history for zsh, some
# implementations of which exist in bash[1,2]. It also implements
# a per-directory-history-toggle-history function to change from using the
# directory history to using the global history. In both cases the history is
# always saved to both the global history and the directory history, so the
# toggle state will not effect the saved histories. Being able to switch
# between global and directory histories on the fly is a novel feature as far
# as I am aware.
#
#-------------------------------------------------------------------------------
# Configuration
#-------------------------------------------------------------------------------
#
# HISTORY_BASE a global variable that defines the base directory in which the
# directory histories are stored
#
#-------------------------------------------------------------------------------
# History
#-------------------------------------------------------------------------------
#
# The idea/inspiration for a per directory history is from Stewart MacArthur[1]
# and Dieter[2], the implementation idea is from Bart Schaefer on the the zsh
# mailing list[3]. The implementation is by Jim Hester in September 2012.
#
# [1]: http://www.compbiome.com/2010/07/bash-per-directory-bash-history.html
# [2]: http://dieter.plaetinck.be/per_directory_bash
# [3]: http://www.zsh.org/mla/users/1997/msg00226.html
#
################################################################################
#
# Copyright (c) 2012 Jim Hester
#
# This software is provided 'as-is', without any express or implied warranty.
# In no event will the authors be held liable for any damages arising from the
# use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not claim
# that you wrote the original software. If you use this software in a product,
# an acknowledgment in the product documentation would be appreciated but is
# not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source distribution..
#
################################################################################
#-------------------------------------------------------------------------------
# configuration, the base under which the directory histories are stored
#-------------------------------------------------------------------------------
[[
-z
$HISTORY_BASE
]]
&&
HISTORY_BASE
=
"
$HOME
/.directory_history"
#-------------------------------------------------------------------------------
# toggle global/directory history used for searching - ctrl-G by default
#-------------------------------------------------------------------------------
function
per-directory-history-toggle-history
()
{
if
[[
$_per_directory_history_is_global
==
true
]]
;
then
_per-directory-history-set-directory-history
echo
"using local history
\n
"
else
_per-directory-history-set-global-history
echo
"using global history
\n
"
fi
zle reset-prompt
}
autoload per-directory-history-toggle-history
zle
-N
per-directory-history-toggle-history
bindkey
'^G'
per-directory-history-toggle-history
#-------------------------------------------------------------------------------
# implementation details
#-------------------------------------------------------------------------------
_per_directory_history_directory
=
"
$HISTORY_BASE
${
PWD
:A
}
/history"
function
_per-directory-history-change-directory
()
{
_per_directory_history_directory
=
"
$HISTORY_BASE
${
PWD
:A
}
/history"
mkdir
-p
${
_per_directory_history_directory
:h
}
if
[[
$_per_directory_history_is_global
==
false
]]
;
then
#save to the global history
fc
-AI
$HISTFILE
#save history to previous file
local
prev
=
"
$HISTORY_BASE
${
OLDPWD
:A
}
/history"
mkdir
-p
${
prev
:h
}
fc
-AI
$prev
#discard previous directory's history
local
original_histsize
=
$HISTSIZE
HISTSIZE
=
0
HISTSIZE
=
$original_histsize
#read history in new file
if
[[
-e
$_per_directory_history_directory
]]
;
then
fc
-R
$_per_directory_history_directory
fi
fi
}
function
_per-directory-history-addhistory
()
{
print
-sr
--
${
1
%%
$'
\n
'
}
fc
-p
$_per_directory_history_directory
}
function
_per-directory-history-set-directory-history
()
{
if
[[
$_per_directory_history_is_global
==
true
]]
;
then
fc
-AI
$HISTFILE
local
original_histsize
=
$HISTSIZE
HISTSIZE
=
0
HISTSIZE
=
$original_histsize
if
[[
-e
"
$_per_directory_history_directory
"
]]
;
then
fc
-R
"
$_per_directory_history_directory
"
fi
fi
_per_directory_history_is_global
=
false
}
function
_per-directory-history-set-global-history
()
{
if
[[
$_per_directory_history_is_global
==
false
]]
;
then
fc
-AI
$_per_directory_history_directory
local
original_histsize
=
$HISTSIZE
HISTSIZE
=
0
HISTSIZE
=
$original_histsize
if
[[
-e
"
$HISTFILE
"
]]
;
then
fc
-R
"
$HISTFILE
"
fi
fi
_per_directory_history_is_global
=
true
}
#add functions to the exec list for chpwd and zshaddhistory
chpwd_functions
=(
${
chpwd_functions
[@]
}
"_per-directory-history-change-directory"
)
zshaddhistory_functions
=(
${
zshaddhistory_functions
[@]
}
"_per-directory-history-addhistory"
)
#start in directory mode
mkdir
-p
${
_per_directory_history_directory
:h
}
_per_directory_history_is_global
=
true
_per-directory-history-set-directory-history
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录