Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Aggregated logs in single file #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#IDE's files
.idea
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ Usage
Configuration
-------------------------------------------------------------------------------

* HISTORY_BASE a global variable that defines the base directory in which the
* `HISTORY_BASE` a global variable that defines the base directory in which the
directory histories are stored
* per-directory-history-toggle-history is the function to toggle the history
* `PER_DIRECTORY_AGGREGATED_PATH` if exist then fixed history file path is used:
`$HISTORY_BASE/$PER_DIRECTORY_AGGREGATED_PATH`

Good if you would like to keep your history aggregated for multiple directories
(use `direnv` to set that ENV depended on the directory)
* `per-directory-history-toggle-history` is the function to toggle the history

-------------------------------------------------------------------------------
History
Expand Down
23 changes: 18 additions & 5 deletions per-directory-history.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# configuration, the base under which the directory histories are stored
#-------------------------------------------------------------------------------

[[ -z $HISTORY_BASE ]] && HISTORY_BASE="$HOME/.directory_history"
[[ -z $HISTORY_BASE ]] && HISTORY_BASE="$HOME/.config/directory_history"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to change the default for history base I think it needs to be discussed in a separate PR.

It should also probably use $XDG_CONFIG_HOME with a fallback to $HOME/.config if XDG_CONFIG_HOME is not set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can revert that HISTORY_BASE change.
Let me know if you have more remarks

[[ -z $HISTORY_START_WITH_GLOBAL ]] && HISTORY_START_WITH_GLOBAL=false
[[ -z $PER_DIRECTORY_HISTORY_TOGGLE ]] && PER_DIRECTORY_HISTORY_TOGGLE='^G'

Expand Down Expand Up @@ -85,17 +85,30 @@ bindkey $PER_DIRECTORY_HISTORY_TOGGLE per-directory-history-toggle-history
#-------------------------------------------------------------------------------
# implementation details
#-------------------------------------------------------------------------------

_per_directory_history_directory="$HISTORY_BASE${PWD:A}/history"
function load_dir_history_path() {
if [[ -z $PER_DIRECTORY_AGGREGATED_PATH ]]
then
_per_directory_history_directory="$HISTORY_BASE${PWD:A}/history"
else
_per_directory_history_directory="$HISTORY_BASE/$PER_DIRECTORY_AGGREGATED_PATH"
fi
}
load_dir_history_path

function _per-directory-history-change-directory() {
_per_directory_history_directory="$HISTORY_BASE${PWD:A}/history"
load_dir_history_path
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"
if [[ -z $PER_DIRECTORY_AGGREGATED_PATH ]]
then
local prev="$HISTORY_BASE${OLDPWD:A}/history"
else
local prev=$_per_directory_history_directory
fi
mkdir -p ${prev:h}
fc -AI $prev

Expand Down