commit c18132f

hovercats  ·  2023-01-16 20:30:28 +0000 UTC
parent c25a698
dsearch: fix if $STRING is empty not exiting if its empty. nits
1 files changed,  +8, -16
+8, -16
 1@@ -1,26 +1,18 @@
 2 #!/bin/sh -e
 3 
 4-# A really simple script to search the web, from dmenu with your browser and
 5-# search engine of choice.
 6-# It will only handle search strings, which means if you type an actual URL,
 7-# $BROWSER will then search for that string on $ENGINE.
 8+# Search the web from dmenu
 9+# Does not handle URLs
10 
11-# Change this to w/e floats your boat.
12-BROWSER=$BROWSER
13+# shellcheck disable=2153
14+browser="$BROWSER"
15 
16-# You can change this to w/e searchengine you like, aslong as its similarly
17-# formatted as below.
18-# Check your searchengine to be sure.
19 ENGINE='https://duckduckgo.com/?q='
20 
21-# Set search string as a variable, and remove spaces, as we cant have any spaces
22-# in our URL. Also make sure the substitution is correct if you change to a
23-# different search engine as they might not be the same.
24+# Spaces are not allowed, so substitute them to correct string
25 STRING=$(printf '' | dmenu -p 'Search' | sed 's/ /%20/g')
26 
27-# exit if $STRING is empty.
28-if [ "$STRING" = '' ]; then
29-    exit 0
30+if [ -z "$STRING" ]; then
31+    exit 1
32 else
33-    $BROWSER "$ENGINE$STRING"
34+    "$browser" "$ENGINE$STRING"
35 fi