12 Commits

Author SHA1 Message Date
  Alois Mahdal e75c4b45d6 Bump version 5 years ago
  Alois Mahdal e5c2c211f9 Fix syntax error in debian/control 5 years ago
  Alois Mahdal fcd7da8d05 Bump version 5 years ago
  Alois Mahdal 76ccd1c093 Add missing file listings 5 years ago
  Alois Mahdal 7b7cc4b4a9 Add missing Perl dependencies 5 years ago
  Alois Mahdal 4e2cc49d13 Fix typo in .spec file 5 years ago
  Alois Mahdal 75dd46520b Bump version 5 years ago
  Alois Mahdal 0bec8ed937 Jump to first object mention in object mode 5 years ago
  Alois Mahdal e5f1740095 Add third import group for consistency with PEP8 5 years ago
  Alois Mahdal 13ac645e1e Remove leftover debug junk 5 years ago
  Alois Mahdal 508911f0b1 Fix typo 5 years ago
  Alois Mahdal e2214d4c0f Add coerce.sh for character set coercion 5 years ago

+ 1
- 1
README.md View File

87
 Next, if you have also installed some modules, you can look around
87
 Next, if you have also installed some modules, you can look around
88
 using `sfdoc`:
88
 using `sfdoc`:
89
 
89
 
90
-    sfdoc --lsmods
90
+    sfdoc --lsmod
91
     sfdoc inigrep
91
     sfdoc inigrep
92
 
92
 
93
 This is how you access documentation of modules available on the system.
93
 This is how you access documentation of modules available on the system.

+ 1
- 1
mkit.ini View File

1
 [project]
1
 [project]
2
-    version     = 0.10.12
2
+    version     = 0.10.15
3
     codename    = FloatingPointError
3
     codename    = FloatingPointError
4
     name        = Shellfu
4
     name        = Shellfu
5
     tagline     = Shell dot on steroids
5
     tagline     = Shell dot on steroids

+ 1
- 0
notes/style.md View File

84
 
84
 
85
  1. standard library modules,
85
  1. standard library modules,
86
  2. related third party modules,
86
  2. related third party modules,
87
+ 3. local application/library specific imports,
87
 
88
 
88
 with empty line between the groups, and each group being sorted
89
 with empty line between the groups, and each group being sorted
89
 alphabetically.
90
 alphabetically.

+ 20
- 0
packaging/debian/control View File

172
  This sub-package contains 'charmenu', a Shellfu/sh module for building
172
  This sub-package contains 'charmenu', a Shellfu/sh module for building
173
  interactive terminal menus
173
  interactive terminal menus
174
 
174
 
175
+Package: shellfu-sh-coerce
176
+Architecture: all
177
+Depends:
178
+ shellfu-sh,
179
+ perl,
180
+ perl-modules,
181
+Description: Shellfu/sh module with data coercion helpers
182
+ Shellfu is an attempt to add modularity to your shell scripts.
183
+ .
184
+ With Shellfu you can develop your shell modules separately from your
185
+ scripts, and test, use, explore or study them without need to be aware
186
+ of details such as where the actual files are placed.
187
+ .
188
+ Shellfu is mostly intended for cases when there's need for non-trivial
189
+ amount of reliable body of shell scripts, and access to advanced modular
190
+ languages such as Python or Perl is limited.
191
+ .
192
+ This sub-package contains 'coerce', Shellfu module containing few
193
+ data coercion helpers.
194
+
175
 Package: shellfu-sh-exit
195
 Package: shellfu-sh-exit
176
 Architecture: all
196
 Architecture: all
177
 Depends: shellfu-sh
197
 Depends: shellfu-sh

+ 1
- 0
packaging/debian/shellfu-sh-coerce.install View File

1
+/usr/share/shellfu/include-sh/coerce.sh

+ 12
- 0
packaging/template.spec View File

97
 This sub-package contains 'charmenu', a Shellfu/sh module for building
97
 This sub-package contains 'charmenu', a Shellfu/sh module for building
98
 interactive terminal menus
98
 interactive terminal menus
99
 
99
 
100
+%package sh-coerce
101
+Summary: Shellfu/sh module with data coercion helpers
102
+Requires: perl
103
+Requires: perl-Term-ANSIColor
104
+Requires: shellfu-sh
105
+%description sh-coerce
106
+This sub-package contains 'coerce', Shellfu module containing few
107
+data coercion helpers.
108
+
100
 %package sh-exit
109
 %package sh-exit
101
 Summary: Shellfu/sh module for standard exit statuses
110
 Summary: Shellfu/sh module for standard exit statuses
102
 Requires: shellfu-sh
111
 Requires: shellfu-sh
181
 %files sh-charmenu
190
 %files sh-charmenu
182
 %{_datadir}/%{name}/include-sh/charmenu.sh
191
 %{_datadir}/%{name}/include-sh/charmenu.sh
183
 
192
 
193
+%files sh-coerce
194
+%{_datadir}/%{name}/include-sh/coerce.sh
195
+
184
 %files sh-exit
196
 %files sh-exit
185
 %{_datadir}/%{name}/include-sh/exit.sh
197
 %{_datadir}/%{name}/include-sh/exit.sh
186
 
198
 

+ 7
- 2
src/bin/sfdoc View File

93
     local RealModuleName    # name to override eg. if accessing via filename
93
     local RealModuleName    # name to override eg. if accessing via filename
94
     local encoding          # encoding
94
     local encoding          # encoding
95
     local mpath             # path to module file
95
     local mpath             # path to module file
96
+    local jump              # jump to first occurence of this
96
     action=man
97
     action=man
97
     format=markdown
98
     format=markdown
98
     encoding=utf8
99
     encoding=utf8
125
     esac
126
     esac
126
     case $spectype in
127
     case $spectype in
127
         obj) module=$(find_by "$mspec") \
128
         obj) module=$(find_by "$mspec") \
128
-              || die "no module found with: $mspec" ;;
129
+              || die "no module found with: $mspec"
130
+             jump="$mspec"
131
+             ;;
129
         *)   module=$mspec ;;
132
         *)   module=$mspec ;;
130
     esac
133
     esac
131
     case $action in
134
     case $action in
164
              || die "pod2man is missing; cannot use man page mode"
167
              || die "pod2man is missing; cannot use man page mode"
165
             manfile=$(mktemp -t "sfdoc.manfile.XXXXXXXX")
168
             manfile=$(mktemp -t "sfdoc.manfile.XXXXXXXX")
166
             sfdoc__export manpage "${RealModuleName:-$module}" "$mpath" "$encoding" >"$manfile"
169
             sfdoc__export manpage "${RealModuleName:-$module}" "$mpath" "$encoding" >"$manfile"
167
-            man "$manfile"
170
+            manless="$LESS"
171
+            test -n "$jump" && manless+=" +/$jump"
172
+            LESS="$manless" man "$manfile"
168
             rm "$manfile"
173
             rm "$manfile"
169
             ;;
174
             ;;
170
         src)
175
         src)

+ 0
- 7
src/complete.bash View File

44
                                       && __sfdoc_compgen_M3  ;;
44
                                       && __sfdoc_compgen_M3  ;;
45
         esac
45
         esac
46
     )
46
     )
47
-    {
48
-        declare -p cur
49
-        declare -p prev
50
-        declare -p COMP_CWORD
51
-        declare -p COMP_WORDS
52
-        declare -p crtext
53
-    } >/tmp/__sfdoc__compgen
54
     COMPREPLY=(
47
     COMPREPLY=(
55
         $(compgen -W "$crtext" -- "$cur")
48
         $(compgen -W "$crtext" -- "$cur")
56
     )
49
     )

+ 79
- 0
src/include-sh/coerce.sh View File

1
+#!/bin/sh
2
+
3
+#
4
+# Data coercion helpers
5
+#
6
+# This module provides several simple functions to help transform
7
+# data to fit certain constraints.
8
+#
9
+
10
+#
11
+# Replacement character
12
+#
13
+COERCE__REPCHAR=${COERCE__REPCHAR:-�}
14
+
15
+coerce__nocolor() {
16
+    #
17
+    # Remove ANSI color codes
18
+    #
19
+    perl -CS -Mutf8 -MTerm::ANSIColor=colorstrip -ne 'print colorstrip $_;'
20
+}
21
+
22
+coerce__noctl() {
23
+    #
24
+    # Remove non-printable characters
25
+    #
26
+    perl -CS -Mutf8 -pe 'tr|[:graph:]\n\t ||c;'
27
+}
28
+
29
+coerce__nofdraw() {
30
+    #
31
+    # Replace frame-drawing characters with ASCII
32
+    #
33
+    # Replace frame-drawing characters according
34
+    # to following mapping:
35
+    #
36
+    #     ┌ ┬ ┐ └ ┴ ┘ ├ ┤ │ ┼ ─
37
+    #
38
+    #     ' ' ' . . . | | | | -
39
+    #
40
+    # This converts frame-drawing to ASCII, making it
41
+    # safer when fonts on terminals are not rendering
42
+    # properly.
43
+    #
44
+    perl -CS -Mutf8 -pe "
45
+        tr{┌┬┐}{.};
46
+        tr{└┴┘}{'};
47
+        tr{├┼┤│}{|};
48
+        tr{─}{-};
49
+    "
50
+}
51
+
52
+coerce__for_yaml() {
53
+    #
54
+    # Replace yaml-invalid characters
55
+    #
56
+    # Yaml won't allow all characters:
57
+    #
58
+    # > [...] The allowed character range explicitly excludes the C0 control
59
+    # > block #x0-#x1F (except for TAB #x9, LF #xA, and CR #xD which are
60
+    # > allowed), DEL #x7F, the C1 control block #x80-#x9F (except for NEL
61
+    # > #x85 which is allowed), the surrogate block #xD800-#xDFFF, #xFFFE,
62
+    # > and #xFFFF.
63
+    #
64
+    # so take stdin and replace all unacceptable characters with '�'.
65
+    #
66
+    perl -CS -Mutf8 -pe "tr/$(__coerce__for_yaml_bad)/$COERCE__REPCHAR/"
67
+}
68
+
69
+__coerce__for_yaml_bad() {
70
+    #
71
+    # Print all YAML-bad chars
72
+    #
73
+    printf '\N{U+0}-\N{U+8}\N{U+B}\N{U+C}\N{U+E}-\N{U+1F}'    # C0 with some gaps
74
+    printf '\N{U+7F}'                                         # DEL alone
75
+    printf '\N{U+80}-\N{U+84}\N{U+86}-\N{U+9F}'               # C1 with NEL gap
76
+    # printf -n '\N{U+D800}-\N{U+DFFF}'                        # surrogates
77
+    # printf -n '\N{U+FFFE}-\N{U+FFFF}'                        # 0xFFFE and 0xFFFF
78
+    #FIXME: for some reasons perl complains about these ^^
79
+}