Skip to content

Commit 2de5c41

Browse files
committed
0.1.2
1 parent 8e48849 commit 2de5c41

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- 0.1.2
2+
- cleaned code
13
- 0.1.1
24
- modified test option (now, test option tries to find "./test/" and "./tests/" folders)
35
- 0.1.0

functions/source-fish.fish

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ function source-fish -d "Source fish files under the current directory"
44
'v/version' 'h/help' 'a/all' 't/test' 'c/config' -- $argv
55
or return
66

7-
set --local version_source_fish "v0.1.1"
7+
set --local version_source_fish "v0.1.2"
88
# color shortcut
99
set --local cc (set_color yellow)
1010
set --local cn (set_color normal)
1111
set --local ca (set_color cyan)
12-
set --local test_flag
13-
set --local max_find_depth "-3"
1412

15-
# input arguments
16-
set --local directory $argv
13+
set --local directory $argv # input arguments
14+
set --local max_find_depth "-3" # find depth
15+
set --local test_flag
1716

1817
if set -q _flag_version
1918
echo "source-fish:" $version_source_fish
@@ -22,23 +21,23 @@ function source-fish -d "Source fish files under the current directory"
2221
__source-fish_help
2322
return
2423
else if test -n "$directory"
25-
## if arguments specified, find fish files in the directories
26-
### split last slash character
27-
set --local list_escaped (string replace --all -r "/\$" "" $directory)
28-
set --local list_specied_dir_files
29-
for i in (seq 1 (count $list_escaped))
30-
set -a list_specied_dir_files (command find . -depth $max_find_depth -type f -path "./$list_escaped[$i]/*.fish")
24+
## if arguments aer specified, find fish files in the directories
25+
### trim last slash character
26+
set --local list_replaced (string replace --all -r "/\$" "" $directory)
27+
set --local list_specified_dir_files
28+
for i in (seq 1 (count $list_replaced))
29+
set -a list_specified_dir_files (command find . -depth $max_find_depth -type f -path "./$list_replaced[$i]/*.fish")
3130
end
32-
if not test -n "$list_specied_dir_files"
31+
if not test -n "$list_specified_dir_files"
3332
echo "can't find any fish files"
3433
return 1
3534
end
36-
printf '%s\n' "found fish files:"$cc $list_specied_dir_files; set_color normal
35+
printf '%s\n' "found fish files:"$cc $list_specified_dir_files; set_color normal
3736
while true
3837
read -l -P "Source these fish files? [Y/n]: " question
3938
switch "$question"
4039
case Y y yes
41-
__source-fish_times $list_specied_dir_files
40+
__source-fish_times $list_specified_dir_files
4241
return
4342
case N n q no
4443
return 1
@@ -78,6 +77,7 @@ function source-fish -d "Source fish files under the current directory"
7877
set --local list_test_dir
7978
set -a list_test_dir (command find . -type f -depth $max_find_depth -path "./test/*.fish")
8079
set -a list_test_dir (command find . -type f -depth $max_find_depth -path "./tests/*.fish")
80+
# set -a list_test_dir (command find . -type f -depth $max_find_depth -name "*test.fish")
8181
if not test -n "$list_test_dir"
8282
echo "can't find any fish files"
8383
return 1
@@ -118,7 +118,6 @@ function source-fish -d "Source fish files under the current directory"
118118
return 1
119119
end
120120
end
121-
122121
while true
123122
read -l -P "Source? [s/source | l/ls&source | t/test | b/back | e/exit ]: " question
124123
switch "$question"
@@ -147,7 +146,7 @@ function source-fish -d "Source fish files under the current directory"
147146
set --local list_functions (command find . -type f -depth $max_find_depth -path "./functions/*.fish")
148147
set --local list_completions (command find . -type f -depth $max_find_depth -path "./completions/*.fish")
149148
set --local list_conf (command find . -type f -depth $max_find_depth -path "./conf.d/*.fish")
150-
149+
151150
test -n "$list_functions"
152151
and __source-fish_times $list_functions
153152
and set test_flag "OK"
@@ -169,7 +168,8 @@ function source-fish -d "Source fish files under the current directory"
169168
end
170169

171170

172-
# helper function
171+
# helper functions
172+
## main function (source wrapper)
173173
function __source-fish_times
174174
argparse 'quiet' 'test' -- $argv
175175
or return 1
@@ -178,18 +178,18 @@ function __source-fish_times
178178
set --local cn (set_color normal)
179179
set --local ca (set_color cyan)
180180

181-
if set -q _flag_quiet
181+
if set -q _flag_test
182182
for i in (seq 1 (count $argv))
183-
builtin source $argv[$i]
183+
echo $ca"-->found:"$cc $argv[$i] $cn
184184
end
185-
else if set -q _flag_test
185+
else if set -q _flag_quiet
186186
for i in (seq 1 (count $argv))
187-
echo $ca"-->found:"$cc $argv[$i] $cn
187+
builtin source $argv[$i]
188188
end
189189
else
190190
for i in (seq 1 (count $argv))
191191
builtin source $argv[$i]
192-
and echo $ca"-->complete:"$cc $argv[$i] $cn
192+
and echo $ca"-->completed:"$cc $argv[$i] $cn
193193
end
194194
end
195195
end

0 commit comments

Comments
 (0)