Bläddra i källkod

Add -s|--src for easy viewing of module source

Alois Mahdal 6 år sedan
förälder
incheckning
5ae76898dc
3 ändrade filer med 27 tillägg och 0 borttagningar
  1. 1
    0
      packaging/debian/control
  2. 1
    0
      packaging/template.spec
  3. 25
    0
      src/bin/sfdoc

+ 1
- 0
packaging/debian/control Visa fil

12
 Package: __MKIT_PROJ_PKGNAME__
12
 Package: __MKIT_PROJ_PKGNAME__
13
 Architecture: all
13
 Architecture: all
14
 Depends:
14
 Depends:
15
+ source-highlight,
15
  perl,
16
  perl,
16
  procps,
17
  procps,
17
 Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
18
 Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__

+ 1
- 0
packaging/template.spec Visa fil

16
 BuildRequires:  %{pspkg}
16
 BuildRequires:  %{pspkg}
17
 
17
 
18
 Requires: %{pspkg}
18
 Requires: %{pspkg}
19
+Requires: source-highlight
19
 %description
20
 %description
20
 Shellfu is an attempt to add modularity to your shell scripts.
21
 Shellfu is an attempt to add modularity to your shell scripts.
21
 
22
 

+ 25
- 0
src/bin/sfdoc Visa fil

14
         "[options] --ls{var|fun} MODULE"                                \
14
         "[options] --ls{var|fun} MODULE"                                \
15
         "[options] --which"                                             \
15
         "[options] --which"                                             \
16
         "[options] --lsmod"                                             \
16
         "[options] --lsmod"                                             \
17
+        "[options] -s|--src MODULE"                                     \
17
         "[options] --export FMT MODULE"                                 \
18
         "[options] --export FMT MODULE"                                 \
18
         -c                                                              \
19
         -c                                                              \
19
             "-l, --ls [MODULE]  list contents of MODULE if specified,"  \
20
             "-l, --ls [MODULE]  list contents of MODULE if specified,"  \
22
             " --lsfun MODULE    show list of functions in MODULE"       \
23
             " --lsfun MODULE    show list of functions in MODULE"       \
23
             " --lsvar MODULE    show list of variables in MODULE"       \
24
             " --lsvar MODULE    show list of variables in MODULE"       \
24
             " --which MODULE    show path to MODULE file"               \
25
             " --which MODULE    show path to MODULE file"               \
26
+            "-s, --src MODULE   show MODULE source code"                \
25
             "-e, --export FMT MODULE   export MODULE documentation in"  \
27
             "-e, --export FMT MODULE   export MODULE documentation in"  \
26
             "                   format FMT: 'markdown', 'manpage' and"  \
28
             "                   format FMT: 'markdown', 'manpage' and"  \
27
             "                   'pod' are supported"                    \
29
             "                   'pod' are supported"                    \
59
     echo "$mfile"
61
     echo "$mfile"
60
 }
62
 }
61
 
63
 
64
+find_lesspipe() {
65
+    #
66
+    # Output correct path to src-hilite-lesspipe.sh
67
+    #
68
+    find \
69
+      /usr/bin/src-hilite-lesspipe.sh \
70
+      /usr/share/source-highlight/src-hilite-lesspipe.sh \
71
+     2>/dev/null
72
+}
73
+
62
 main() {
74
 main() {
63
     local action            # what to do
75
     local action            # what to do
64
     local format            # export format
76
     local format            # export format
75
         -d|--debug)     PRETTY_DEBUG=true;          shift ;;
87
         -d|--debug)     PRETTY_DEBUG=true;          shift ;;
76
         -a|--all)       SFDOC_SHOW_HIDDEN=true;     shift ;;
88
         -a|--all)       SFDOC_SHOW_HIDDEN=true;     shift ;;
77
         -I|--include)   SHELLFU_PATH="$2:$SHELLFU_PATH"; shift 2 || usage ;;
89
         -I|--include)   SHELLFU_PATH="$2:$SHELLFU_PATH"; shift 2 || usage ;;
90
+        -s|--src)       action=src;                 shift; break ;;
78
         -l|--ls)        action=lsx;                 shift; break ;;
91
         -l|--ls)        action=lsx;                 shift; break ;;
79
         -L|--lsmod)     action=lsm;                 shift; break ;;
92
         -L|--lsmod)     action=lsm;                 shift; break ;;
80
         --which)        action=wch;                 shift; break ;;
93
         --which)        action=wch;                 shift; break ;;
131
             sfdoc__export manpage "${RealModuleName:-$module}" "$mpath" "$encoding" \
144
             sfdoc__export manpage "${RealModuleName:-$module}" "$mpath" "$encoding" \
132
               | man -l -
145
               | man -l -
133
             ;;
146
             ;;
147
+        src)
148
+            local lesspipe
149
+            lesspipe=$(find_lesspipe)
150
+            if test -n "$lesspipe";
151
+            then
152
+                LESS="$LESS -R " \
153
+                LESSOPEN="| $lesspipe %s" \
154
+                    less "$mpath"
155
+            else
156
+                less "$mpath"
157
+            fi
158
+            ;;
134
         wch)
159
         wch)
135
             select_mfile "$module"
160
             select_mfile "$module"
136
             ;;
161
             ;;