Skip to content

Commit

Permalink
neet, README.md: Add debug option, fix find maxdepth, assign matches …
Browse files Browse the repository at this point in the history
…variable differently (without a read, which didn't seem to work).
  • Loading branch information
onodera-punpun committed Mar 15, 2016
1 parent a9459dd commit f0b3ed3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ the `-r` argument, this is done for two reasons:
```
neet [options] [-/+]
-e, --edit edit list
-d, --debug print some helpful debug ouput
-r, --realias forgets current alias
-h, --help print help and exit
```
Expand Down
83 changes: 66 additions & 17 deletions neet
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,71 @@ function info
set -g current (string match -r -a '[0-9]+' $active[2] | head -n 1)
end
set -g total (string match -r -a '[0-9]+' $active[2] | tail -n 1)

# Debug output
if test $debug = true
echo 'function info'
echo " name = $name"
echo " current = $current"
echo " total = $total"
echo

return
end
end

# This function tries to fuzzy find the right directory
function directory
source $configdir/alias

# Check if the show already has an alias
if string match -r -q $name $alias[1]; and test $realias = false
if string match -r -q $name $alias[1]; and test $realias = false -a $debug = false
set -g path $alias[2]
return
end

# Lists all directories in mediadir
set -g directories (find $mediadir/* -maxdepth 1 -type d | string replace -r '.*/' '')
set -g directories (find $mediadir/* -maxdepth 0 -type d | string replace -r '.*/' '')

# This is the actual fuzzy logic part, it compares the directory names with the active show name
for directory in $directories
set match 0

for word in (string split ' ' $name)
set wordmatch (string match -r -i -a -n $word $directory | string replace -r '.* ' '')
if test $status -ge 1
continue
set matches (
for directory in $directories
set match 0

for word in (string split ' ' $name)
set wordmatch (string match -r -i -a -n $word $directory | string replace -r '.* ' '')
if test $status -ge 1
continue
end
set wordmatch (string join ' + ' $wordmatch)

set match (math $match + $wordmatch)
end
set wordmatch (string join ' + ' $wordmatch)

set match (math $match + $wordmatch)
end

echo $match $directory
end | sort -n | read matches
echo $match $directory
end | sort -n
)

# This gets the output with the most matches
set -g path (echo $matches[-1] | cut -d ' ' -f 2-)

# Debug output
if test $debug = true
echo 'function directory'
echo " path = $path"
echo ' directories ='
for line in $directories
echo " $line"
end
echo ' matches ='
for line in $matches
echo " $line"
end
echo

return
end

# Create alias
if test -n $path
echo 'Show initialized. (alias set)'
Expand All @@ -108,6 +138,19 @@ function episode
set -g file (string match -r -i '.*[0]*'$current'[^0-9].*$' $episodes)
end

# Debug output
if test $debug = true
echo 'function episode'
echo " file = $file"
echo ' episodes ='
for line in $episodes
echo " $line"
end
echo

return
end

# Throw error if no file is found
if test -z $file[1]
echo 'No '(set_color $highlight)'episode'(set_color normal)' match.'
Expand Down Expand Up @@ -137,6 +180,7 @@ end
init
source $configdir/config

set debug false
set realias false

if test (count $argv) -eq 1
Expand All @@ -145,16 +189,21 @@ if test (count $argv) -eq 1
echo -e 'Usage: neet [options] [-/+]\n'
echo 'options:'
echo ' -e, --edit edit list'
echo ' -d, --debug print some helpful debug ouput'
echo ' -r, --realias forgets current alias'
echo ' -h, --help print help and exit'
exit 0
case -e --edit
eval $EDITOR $configdir/list
exit 0
case -r --realias
info
case -d --debug
set debug true

info
case -r --realias
set realias true

info
case '+*'
# Fail if there is a non + character in argv
if test -n (string replace -a '+' '' $argv[1])
Expand Down

0 comments on commit f0b3ed3

Please sign in to comment.