Skip to content

Commit

Permalink
use all available sources by default
Browse files Browse the repository at this point in the history
  • Loading branch information
filiparag committed Sep 2, 2020
1 parent 3b2d23b commit 63d620d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 25 deletions.
8 changes: 7 additions & 1 deletion sources/arch.sh
Expand Up @@ -3,9 +3,15 @@
name='arch'
path='/usr/share/doc/arch-wiki/html'

available() {

[ -d "$path" ]

}

info() {

if [ -d "$path" ]; then
if available; then
state="$(echo "$conf_sources" | grep -qP "$name" && echo "+")"
count="$(find "$path" -type f | wc -l)"
printf '%-10s %3s %8i %s\n' "$name" "$state" "$count" "$path"
Expand Down
8 changes: 7 additions & 1 deletion sources/fbsd.sh
Expand Up @@ -3,9 +3,15 @@
name='fbsd'
path='/usr/share/doc/freebsd-docs'

available() {

[ -d "$path" ]

}

info() {

if [ -d "$path" ]; then
if available; then
state="$(echo "$conf_sources" | grep -qP "$name" && echo "+")"
count="$(find "$path" -type f | wc -l)"
printf '%-10s %3s %8i %s\n' "$name" "$state" "$count" "$path"
Expand Down
8 changes: 7 additions & 1 deletion sources/gentoo.sh
Expand Up @@ -3,9 +3,15 @@
name='gentoo'
path='/usr/share/doc/gentoo-wiki/wiki'

available() {

[ -d "$path" ]

}

info() {

if [ -d "$path" ]; then
if available; then
state="$(echo "$conf_sources" | grep -qP "$name" && echo "+")"
count="$(find "$path" -type f | wc -l)"
printf '%-10s %3s %8i %s\n' "$name" "$state" "$count" "$path"
Expand Down
8 changes: 7 additions & 1 deletion sources/man.sh
Expand Up @@ -3,9 +3,15 @@
name='man'
path='/usr/share/man'

available() {

[ -d "$path" ]

}

info() {

if [ -d "$path" ]; then
if available; then
state="$(echo "$conf_sources" | grep -qP "$name" && echo "+")"
count="$(find "$path" -type f | wc -l)"
printf '%-10s %3s %8i %s\n' "$name" "$state" "$count" "$path"
Expand Down
4 changes: 2 additions & 2 deletions wikiman.conf
@@ -1,5 +1,5 @@
# Sources
sources = man
# Sources (if empty, use all available)
sources =

# Quick search mode (only by title)
quick_search = false
Expand Down
52 changes: 33 additions & 19 deletions wikiman.sh
Expand Up @@ -108,30 +108,13 @@ init() {
)"
fi

conf_sources="${conf_sources:-man archwiki}"
conf_fuzzy_finder="${conf_fuzzy_finder:-fzf}"
conf_quick_search="${conf_quick_search:-false}"
conf_raw_output="${conf_raw_output:-false}"
conf_man_lang="${conf_man_lang:-en}"
conf_wiki_lang="${conf_wiki_lang:-en}"
conf_tui_preview="${conf_tui_preview:-true}"
conf_tui_keep_open="${conf_tui_keep_open:-false}"
conf_tui_html="${conf_tui_html:-w3m}"

export conf_sources
export conf_quick_search
export conf_raw_output
export conf_man_lang
export conf_wiki_lang
export conf_tui_preview
export conf_tui_keep_open
export conf_tui_html

# Sources

sources_dir="/usr/share/wikiman/sources"
sources_dir_usr="$config_dir/sources"

# Detect source modules

sources="$(
eval "find $sources_dir_usr $sources_dir -type f 2>/dev/null" | \
awk -F '/' \
Expand All @@ -151,6 +134,37 @@ init() {
exit 3
fi

modules="$(echo "$sources" | awk -F '\t' '{print $1}')"
available_sources=""

for mod in $modules; do
module_path="$(echo "$sources" | awk -F '\t' "\$1==\"$mod\" {print \$2}")"
if "$module_path" available; then
available_sources="$available_sources $(basename "$module_path" | cut -d'.' -f1)"
fi
done

# Set configuration variables

conf_sources="${conf_sources:-$available_sources}"
conf_fuzzy_finder="${conf_fuzzy_finder:-fzf}"
conf_quick_search="${conf_quick_search:-false}"
conf_raw_output="${conf_raw_output:-false}"
conf_man_lang="${conf_man_lang:-en}"
conf_wiki_lang="${conf_wiki_lang:-en}"
conf_tui_preview="${conf_tui_preview:-true}"
conf_tui_keep_open="${conf_tui_keep_open:-false}"
conf_tui_html="${conf_tui_html:-w3m}"

export conf_sources
export conf_quick_search
export conf_raw_output
export conf_man_lang
export conf_wiki_lang
export conf_tui_preview
export conf_tui_keep_open
export conf_tui_html

}

combine_results() {
Expand Down

0 comments on commit 63d620d

Please sign in to comment.