sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

externalpipe_buffer.sh (1681B)


      1 #!/usr/bin/env sh
      2 # externalpipe_buffer.sh: use with surf/st externalpipe-signal patches
      3 #   Input Usage: echo st or surf content from externalpipe | ./externalpipe_buffer.sh {st,surf}_strings_read
      4 #   Menus Usage: ./externalpipe_buffer.sh dmenu_{copy, type}
      5 BUFFER_FILE=/tmp/content_buffer
      6 st_strings_read() {
      7   INPUT="$(cat)"
      8   echo "$(
      9     echo "$INPUT" | grep -Eo '\S+' | tr -d '[:blank:]'
     10     echo "$INPUT" | grep -oP '"[^"]+"' | tr -d '"'
     11     echo "$INPUT" | sed 's/^ *[0-9]\+.//g' | awk '{$1=$1};1'
     12   )" | uniq | grep . | awk '{ print length, $0 }' | sort -n -s | cut -d" " -f2- \
     13   >> $BUFFER_FILE &
     14 }
     15 surf_strings_read() {
     16   awk '{printf "%sNEWLINE_REPLACE", $0} END {printf "\n"}' |
     17     xmllint --html --xpath "//*" - |
     18     awk '{ gsub("<[^>]*>", ""); print($0); }' |
     19     sed 's/NEWLINE_REPLACE/↵/g' |
     20     awk '{ gsub("<[^>]*>",""); print $0 }' |
     21     sed 's/&lt;/</g' |
     22     sed 's/&gt;/>/g' |
     23     uniq | grep . | awk '{ print length, $0 }' | sort -n -s | cut -d" " -f2- \
     24     >> $BUFFER_FILE &
     25 }
     26 trigger_sigusr1() {
     27   USE_FIFO=F # Recomended as T but only if using dmenu-stdin patch w/ FIFO
     28   rm -f $BUFFER_FILE
     29   if [ $USE_FIFO == T ]; then mkfifo $BUFFER_FILE; else touch $BUFFER_FILE; fi
     30   pkill -USR1 "surf" &
     31   pkill -USR1 "^st$" &
     32   if [ $USE_FIFO != T ]; then sleep 0.8; fi
     33 }
     34 dmenu_copy() {
     35   trigger_sigusr1
     36   cat $BUFFER_FILE | dmenu -l 10 -i -w $(xdotool getactivewindow) -p 'Screen Copy' | sed 's/↵/\n/g' | xclip -i
     37 }
     38 dmenu_type() {
     39   trigger_sigusr1
     40   cat $BUFFER_FILE | dmenu -l 10 -i -w $(xdotool getactivewindow) -p 'Screen Type' | sed 's/↵/\n/g' | xargs -IC xdotool type --delay 0 "C"
     41 }
     42 pipe_combine() {
     43   trigger_sigusr1
     44   cat - $BUFFER_FILE
     45 }
     46 
     47 $1