SHARE
TWEET

Untitled

a guest Dec 7th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #if [ ! -n "$(pgrep bobHelpnotes)" ]; then echo "already running"; exit 1; fi
  3. mkdir -p ~/Helpnotes || exit 1
  4. [ -d ~/.config/Helpnotes ] || mkdir -p ~/.config/Helpnotes
  5. touch ~/.config/Helpnotes/ignored_items.txt || exit 1
  6. ### NOTE: no harm if the blacklist file contains inline working notes
  7. ###  (annotation lines will never exactly match a window titlestring or process name, eh)
  8.  
  9. generate_blacklist_arr() {         #TODO  declare -A, and map
  10.   ### advisable to also USENEVER the name of the tabbed helpviewer app
  11.   usenever=(File Search Replace Open Save SaveAs 'Save As' 'Open As' 'Confirm Delete' \
  12.     'Create New File' Find 'Move Folder' 'Preferences' Question yad Untitled untitled \
  13.     Unnamed unnamed '(Unnamed)' '(unnamed)' 'Choose Font' gExec 'Run Program')
  14.   readarray -t ignored < ~/.config/Helpnotes/ignored_items.txt
  15.   thelist=("${usenever[@]}" "${ignored[@]}")
  16.   #echo ${thelist[@]} ### for debugging
  17. }
  18.  
  19. addtoblacklist_and_reload() {
  20.   ### this fn would be called if user has, via yad dialog, elected to ignore an item
  21.   echo "$now_win" >> ~/.config/Helpnotes/ignored_titles.txt
  22.   exec "./bobHelpnotes"  # new program instance restarts, occupying the same PID, and re-pasrses the blacklist
  23. }
  24.  
  25.  
  26. ###   NOT DYNAMICALLY FILLING-IN-THE BLANK B/C THE TITLETEXT MAY BE LOOOOOONG
  27.   hepmetxt="  context-sensitive help is active, but no note exists yet for ______
  28.  
  29.   Below, you can copy the titletext of the ______ window
  30.   and paste it as the name of a new cherrytree node.
  31.  
  32.  
  33.   tip: to dismiss this dialog, you can ESC or click outside the dialogbox"
  34. trainingmode_ask() {
  35.   sez=$(yad --center --on-top --width=620 --close-on-unfocus --button="OK" --title="scusa" --text="$hepmetxt" \
  36.       --entry --entry-text="$now_win")  ### backgrounding it causes a runaway OOM
  37.   ###  NOTED:  The "--fullscreen" and "--maximize" args are not entirely effective, and are annoying.
  38.   ###          The "close-on-unfocus" option is a godsend, IMO.
  39.   echo $sez
  40.   #  pseudocode:  if return value from the yad call is blah, then do zippity
  41.  
  42.     ### If we are passing a FILEname string (vs a NODEname, passed to cherrytree), might be
  43.     ### advisable (or necessary) to  preface the call with "touch ~/bobHelpnotes/$notename &&"
  44.     ###   ========================
  45.     ### BUT DURING DEBUGGING, UNTIL WE HAVE CREATED A WELL-POPULATED A BLACKLIST
  46.     ### AND/OR SETUP "VALIDATION" RULES TO IGNORE e.g. pythonic endswith(' - Mozilla Firefox')
  47.     ### THE touch WOULD RESULT IN A HELLUVA LOT OF UNWANTED JUNK FILES.
  48. #    touch ~/Helpnotes/$notename && mousepad ~/Helpnotes/${notename}& disown
  49. }
  50.  
  51. generate_blacklist_arr
  52. oldwin=""
  53. xprop -spy -root _NET_ACTIVE_WINDOW | while read -r zig; do
  54.   ###  NOTED: a "goto workspace NN" event generates a change event.
  55.   ###         closure of a transient (e.g "Find" dialog) window generates an event.
  56.   ###  lxterminal: Use of NewWindow command spawns a window titled "Unnamed" yet does NOT generate an event.
  57.   ###              When switching focus between the original and the "Unnamed", no event is detected.
  58.   now_win="$(xdotool getwindowfocus getwindowname)" # window titletext
  59.  
  60.   if [ "$now_win" != "$oldwin" ]; then
  61.     shallreject=0
  62.     for item in "${thelist[@]}"; do
  63.       [[ $now_win == "$item" ]] && $shallreject=1
  64.     done
  65.     [ ! -n shallreject ] && continue # blech
  66.    
  67.     ### sanitize (validate, normalize) the titletext string
  68.     #    ### trim leading // trailing space n tab chars + reduce each whitespace substring to a single space
  69.     notename=$(echo "$now_win"|awk '{$1=$1};1')
  70.     ###  convert punctuation chars
  71.     notename=${notename//[^-_a-zA-Z0-9.]/_}
  72.  
  73.     #trainingmode_ask   ###   WIP   not yet implemented
  74.    
  75.     ###    get the PROCESS NAME associated with the currently-focused window
  76.     echo -e "current processname: $(cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm)"
  77.  
  78.     oldwin="$now_win"
  79.     echo -e "   raw window title: $now_win"
  80.     echo -e "   sanitized notefile namestring:  ~/Helpnotes/$notename"
  81.   fi        ###  The echo lines are useful FOR DEBUGGING
  82. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top