Skip to content

Commit d20b348

Browse files
authored
Merge pull request #186 from b4b4r07/babarot/log-logic
Update log structure logic
2 parents 04222be + efc2daf commit d20b348

8 files changed

Lines changed: 48 additions & 17 deletions

File tree

conf.d/enhancd.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function __enhancd_install --on-event enhancd_install
2222

2323
set -Ux ENHANCD_COMPLETION_KEYBIND "^I"
2424

25-
set -Ux _ENHANCD_VERSION "2.3.0"
25+
set -Ux _ENHANCD_VERSION "2.3.1"
2626

2727
# Set the filters if empty
2828
set -Ux ENHANCD_FILTER "fzy:fzf:peco:percol:sk:zf:gof:selecta"
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
function _enhancd_filepath_walk
2-
if not set -q argv[1]
3-
set argv[1] $PWD
4-
end
2+
set -a dirs ($PWD _enhancd_filepath_get_parent_dirs)
53

6-
command find "$argv[1]" -maxdepth 1 -type d \
7-
| _enhancd_command_grep -v "\/\."
4+
for dir in $dirs
5+
command find "$dir" -maxdepth 1 -type d -name '\.*' -prune -o -type d -print
6+
end
87
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function _enhancd_history_exists
2+
if not set -q argv[1]
3+
return 1
4+
else
5+
set dir $argv[1]
6+
end
7+
8+
_enhancd_history_open | _enhancd_command_grep "$dir" ^/dev/null >/dev/null
9+
end
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
function _enhancd_history_update
22
function sub
3-
_enhancd_filepath_get_parent_dirs | _enhancd_filter_reverse
4-
_enhancd_filepath_walk
3+
_enhancd_history_exists; or _enhancd_filepath_walk
54
_enhancd_history_open
65
echo "$HOME"
76
end
@@ -10,4 +9,4 @@ function _enhancd_history_update
109
| _enhancd_filter_unique \
1110
| _enhancd_filter_reverse
1211
_enhancd_filepath_current_dir
13-
end
12+
end

init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export ENHANCD_COMPLETION_DEFAULT
1717
export ENHANCD_COMPLETION_KEYBIND="${ENHANCD_COMPLETION_KEYBIND:-^I}"
1818
export ENHANCD_COMPLETION_BEHAVIOR="${ENHANCD_COMPLETION_BEHAVIOR:-default}"
1919

20-
export _ENHANCD_VERSION="2.3.0"
20+
export _ENHANCD_VERSION="2.3.1"
2121

2222
if [[ -n ${BASH_VERSION} ]]; then
2323
# BASH

src/cd.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,42 @@ __enhancd::cd()
2323
"${ENHANCD_HYPHEN_ARG}")
2424
# If a hyphen is passed as the argument,
2525
# searchs from the last 10 directory items in the log
26-
args+=( "$(__enhancd::sources::mru "${2}" | __enhancd::filter::interactive)" )
26+
args+=( "$(__enhancd::sources::mru | __enhancd::filter::interactive)" )
2727
code=${?}
28+
break
2829
;;
2930
"-")
3031
# When $ENHANCD_HYPHEN_ARG is configured,
3132
# this behaves like `cd -`
3233
args+=( "${OLDPWD}" )
34+
break
3335
;;
3436
"${ENHANCD_DOT_ARG}")
3537
# If a double-dot is passed as the argument,
3638
# it behaves like a zsh-bd plugin
3739
# In short, you can jump back to a specific directory,
3840
# without doing `cd ../../..`
39-
args+=( "$(__enhancd::sources::parent_dirs "${2}" | __enhancd::filter::interactive)" )
41+
args+=( "$(__enhancd::sources::parent_dirs | __enhancd::filter::interactive)" )
4042
code=${?}
43+
break
4144
;;
4245
"..")
4346
# When $ENHANCD_DOT_ARG is configured,
4447
# ".." is passed to builtin cd
4548
args+=( ".." )
49+
break
4650
;;
4751
"${ENHANCD_HOME_ARG}")
4852
args+=( "$(__enhancd::sources::home | __enhancd::filter::interactive)" )
4953
code=${?}
54+
break
5055
;;
5156
--)
5257
opts+=( "${1}" )
5358
shift
5459
args+=( "$(__enhancd::sources::history "${1}" | __enhancd::filter::interactive)" )
5560
code=${?}
61+
break
5662
;;
5763
-* | --*)
5864
if __enhancd::helper::is_default_flag "${1}"; then

src/filepath.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
# Currently this is not used
22
__enhancd::filepath::split()
33
{
4-
__enhancd::command::awk -f "$ENHANCD_ROOT/functions/enhancd/lib/split.awk" -v arg="${1:-$PWD}"
4+
__enhancd::command::awk -f "${ENHANCD_ROOT}/functions/enhancd/lib/split.awk" -v arg="${1:-$PWD}"
55
}
66

77
__enhancd::filepath::get_parent_dirs()
88
{
9-
__enhancd::command::awk -f "$ENHANCD_ROOT/functions/enhancd/lib/step_by_step.awk" -v dir="${1:-$PWD}"
9+
__enhancd::command::awk -f "${ENHANCD_ROOT}/functions/enhancd/lib/step_by_step.awk" -v dir="${1:-$PWD}"
1010
}
1111

1212
__enhancd::filepath::walk()
1313
{
14-
command find "${1:-$PWD}" -maxdepth 1 -type d -name '\.*' -prune -o -type d -print
14+
local -a dirs
15+
16+
# __enhancd::filepath::get_parent_dirs does not return $PWD itself
17+
# so add it to array expressly
18+
dirs=( "${PWD}" $(__enhancd::filepath::get_parent_dirs "${1:-${PWD}}") )
19+
20+
for dir in "${dirs[@]}"
21+
do
22+
command find "${dir}" -maxdepth 1 -type d -name '\.*' -prune -o -type d -print
23+
done
1524
}
1625

1726
__enhancd::filepath::current_dir()

src/history.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ __enhancd::history::open()
77
return 1
88
}
99

10+
__enhancd::history::exists()
11+
{
12+
local dir="${1}"
13+
if [[ -z ${dir} ]]; then
14+
return 1
15+
fi
16+
17+
__enhancd::history::open | __enhancd::command::grep "${dir}" &>/dev/null
18+
}
19+
1020
__enhancd::history::list()
1121
{
1222
__enhancd::history::open \
@@ -20,8 +30,7 @@ __enhancd::history::list()
2030
__enhancd::history::update()
2131
{
2232
{
23-
__enhancd::filepath::get_parent_dirs | __enhancd::filter::reverse
24-
__enhancd::filepath::walk
33+
__enhancd::history::exists "${PWD}" || __enhancd::filepath::walk
2534
__enhancd::history::open
2635
echo "${HOME}"
2736
} | __enhancd::filter::reverse | __enhancd::filter::unique | __enhancd::filter::reverse

0 commit comments

Comments
 (0)