Browse Source

Merge pull request #1 from jirutka/patch-1

Various improvements
William Pitcock 1 year ago
parent
commit
63f05008b2
No account linked to committer's email
3 changed files with 24 additions and 11 deletions
  1. 15
    0
      .editorconfig
  2. 8
    10
      command-not-found.sh
  3. 1
    1
      profiles/command-not-found.ash

+ 15
- 0
.editorconfig View File

@@ -0,0 +1,15 @@
1
+; See http://editorconfig.org
2
+root = true
3
+
4
+[*]
5
+charset = utf-8
6
+end_of_line = lf
7
+indent_size = 4
8
+indent_style = tab
9
+insert_final_newline = true
10
+trim_trailing_whitespace = true
11
+
12
+[*.md]
13
+indent_size = 2
14
+indent_style = space
15
+trim_trailing_whitespace = false

+ 8
- 10
command-not-found.sh View File

@@ -21,20 +21,18 @@
21 21
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 22
 # SOFTWARE.
23 23
 
24
-results=$(apk search -v "cmd:$1")
25
-results_cnt=$(printf "%s" "$results" | wc -c)
24
+results=$(apk search -xv "cmd:$1" 2>/dev/null)
26 25
 
27
-if [ $results_cnt -gt 0 ]; then
28
-	printf "The program '%s' may be found in these packages:\n" "$1" 1>&2
29
-	printf "%s\n" "$results" | while read line
26
+if [ "$results" ]; then
27
+	printf "The program '%s' may be found in these packages:\n" "$1" >&2
28
+	printf "%s\n" "$results" | while read atom _ desc
30 29
 	do
31
-		atom=$(echo $line | cut -d' ' -f1 | sed -r 's:(.*)-\d.*-r\d:\1:p' | head -n 1)
32
-		desc=$(echo $line | cut -d' ' -f3-)
33
-		printf " * %s: %s\n" "$atom" "$desc" 1>&2
30
+		atom=${atom%-*}; atom=${atom%-*}  # remove version
31
+		printf " * %s: %s\n" "$atom" "$desc" >&2
34 32
 	done
35
-	printf "To install packages: 'apk add <selected package>'\n" 1>&2
33
+	printf "To install packages: 'apk add <selected package>'\n" >&2
36 34
 else
37
-	printf "%s: not found\n" "$1" 1>&2
35
+	printf "%s: not found\n" "$1" >&2
38 36
 fi
39 37
 
40 38
 # POSIX EX_NOTFOUND exit code

+ 1
- 1
profiles/command-not-found.ash View File

@@ -1,4 +1,4 @@
1 1
 command_not_found_handle() {
2 2
 	[ -x /usr/libexec/command-not-found ] || return 0
3
-	/usr/libexec/command-not-found $1
3
+	/usr/libexec/command-not-found "$1"
4 4
 }