소스 검색

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

Alois Mahdal 6 년 전
부모
커밋
5ae76898dc
3개의 변경된 파일27개의 추가작업 그리고 0개의 파일을 삭제
  1. 1
    0
      packaging/debian/control
  2. 1
    0
      packaging/template.spec
  3. 25
    0
      src/bin/sfdoc

+ 1
- 0
packaging/debian/control 파일 보기

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

+ 1
- 0
packaging/template.spec 파일 보기

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

+ 25
- 0
src/bin/sfdoc 파일 보기

@@ -14,6 +14,7 @@ usage() {
14 14
         "[options] --ls{var|fun} MODULE"                                \
15 15
         "[options] --which"                                             \
16 16
         "[options] --lsmod"                                             \
17
+        "[options] -s|--src MODULE"                                     \
17 18
         "[options] --export FMT MODULE"                                 \
18 19
         -c                                                              \
19 20
             "-l, --ls [MODULE]  list contents of MODULE if specified,"  \
@@ -22,6 +23,7 @@ usage() {
22 23
             " --lsfun MODULE    show list of functions in MODULE"       \
23 24
             " --lsvar MODULE    show list of variables in MODULE"       \
24 25
             " --which MODULE    show path to MODULE file"               \
26
+            "-s, --src MODULE   show MODULE source code"                \
25 27
             "-e, --export FMT MODULE   export MODULE documentation in"  \
26 28
             "                   format FMT: 'markdown', 'manpage' and"  \
27 29
             "                   'pod' are supported"                    \
@@ -59,6 +61,16 @@ select_mfile() {
59 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 74
 main() {
63 75
     local action            # what to do
64 76
     local format            # export format
@@ -75,6 +87,7 @@ main() {
75 87
         -d|--debug)     PRETTY_DEBUG=true;          shift ;;
76 88
         -a|--all)       SFDOC_SHOW_HIDDEN=true;     shift ;;
77 89
         -I|--include)   SHELLFU_PATH="$2:$SHELLFU_PATH"; shift 2 || usage ;;
90
+        -s|--src)       action=src;                 shift; break ;;
78 91
         -l|--ls)        action=lsx;                 shift; break ;;
79 92
         -L|--lsmod)     action=lsm;                 shift; break ;;
80 93
         --which)        action=wch;                 shift; break ;;
@@ -131,6 +144,18 @@ main() {
131 144
             sfdoc__export manpage "${RealModuleName:-$module}" "$mpath" "$encoding" \
132 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 159
         wch)
135 160
             select_mfile "$module"
136 161
             ;;