-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiki
executable file
·58 lines (49 loc) · 1.16 KB
/
wiki
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Created by audiodude
# First written April 2020
set -e
shopt -s nocasematch
WIKI_PATH=/usr/share/nginx/html/wiki
if [ -z "$1" ] || [ "$1" == "help" ] || [ "$1" == "--help" ]; then
echo "usage: wiki <article>"
echo " read the article with the given 'short title'"
echo "usage: wiki --list"
echo " list all available short titles"
exit 1
fi
if [ "$1" == "--list" ]; then
ls -1 $WIKI_PATH/*.txt | cut -f 7 -d "/" | cut -f 1 -d "."
echo
echo "Type 'wiki <article> to read that article in your terminal"
echo "...or visit the wiki in your browser at: https://tilde.club/wiki/"
exit 0
fi
# First try concatenating the arguments with "_" to find the path
name=""
for var in "$@"
do
if [ -z "$name" ]; then
name=$var
else
name="${name}_${var}"
fi
done
path="${WIKI_PATH}/${name}.txt"
if [ ! -f $path ]; then
# If that file doesn't exist, try concatentating with "-"
name=""
for var in "$@"
do
if [ -z "$name" ]; then
name=$var
else
name="${name}-${var}"
fi
done
path="${WIKI_PATH}/${name}.txt"
fi
if [ ! -f $path ]; then
echo "Could not find a wiki article with that name"
exit 1
fi
less $path