commit 618327d545e6e3b833222eac25d4ee4e02257bc2
parent 03c5e9441a1e35b2e0a4c705f316c0b1f0dc580b
Author: Chris Down <chris@chrisdown.name>
Date: Wed, 1 Apr 2020 10:36:18 +0100
Merge pull request #91 from ferki/pipe_to_clipdel
clipdel: Support getting pattern from standard input
Diffstat:
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/clipdel b/clipdel
@@ -19,7 +19,8 @@ lock_timeout=2
if [[ $1 == --help ]] || [[ $1 == -h ]]; then
cat << 'EOF'
clipdel deletes clipmenu entries matching a regex. By default, just lists what
-it would delete, pass -d to do it for real.
+it would delete, pass -d to do it for real. If no pattern is passed as an argument,
+it will try to read one from standard input.
".*" is special, it will just nuke the entire data directory, including the
line caches and all other state.
@@ -40,9 +41,12 @@ if ! [[ -f $cache_file ]]; then
exit 0 # Well, this is a kind of success...
fi
-# https://github.com/koalaman/shellcheck/issues/1141
-# shellcheck disable=SC2124
-raw_pattern=$1
+if [[ -n $1 ]]; then
+ raw_pattern=$1
+elif ! [[ -t 0 ]]; then
+ IFS= read -r raw_pattern
+fi
+
esc_pattern=${raw_pattern//\#/'\#'}
# We use 2 separate sed commands so "esc_pattern" matches only the 'clip' text