Есть ли приложение, которое связывает заметки с заметками в окне, на основе названия окна?

После того, как вы переиграли множество вещей и несколько перезагрузок, пропавшие иконки снова появились. Кажется, я понял, что произошло. Я забыл, что сделал следующее (не уверен, что все это имеет значение):

sudo add-apt-repository ppa:jconti/gnome3
sudo apt-get update
sudo apt-get install indicator-applet-complete
sudo reboot

Я думаю, что это решает мою проблему, за исключением того, что было бы неплохо иметь доступ к «Добавить в панель» ". Как я уже говорил выше, специальные щелчки по-прежнему не работают.

2
задан 29 December 2010 в 19:44

14 ответов

Ну, я снова нахожусь на кривой обучения ... (поздние ночи и много кофе).

Конечным результатом является умеренно используемый bash-скрипт (с использованием sqlite db / table), который делает то, что я был после ... ... т.е. Создает группировку заметок, основанных на названиях окон ...

Это работает .. но это определенно «альфа» ..

Итак, у меня есть мое домашнее приложение ! ... Я размещаю его здесь для всех, кто интересуется «смотри-смотри» ...

Вот он:

#!/bin/bash

clearAllDataAndStartAgain="false"

# Name: tinotes (Title Notes)
# 
# What does it do? ... Aside from giving me a great opportunity to learn
#      more about bash (and sqlite, which I had previously barely touched).. not much ;)
#      Actually, it allows you to keep notes, grouped by window title.
#      The notes are kept in an sqlite database. 
#      Each timestamped note-"event" is stored in a row of the main (only) table.
#      You can consolidate notes in a semi ad-hoc manner... 
#      Notes are presented to you in a single editable text file (in Leafpad).  
#      You must keep at least one "tinotes" timestamp-line at the top of the text...
#      All lines above this topmost timestamp-line are ignored,
#      including the "title", which is presented upon each viewing.
#      If you remove any/all other "timestamp line(s)", those particular rows are 
#      deleted from the sqlite table, and the text which remains is associated with
#      the immediately preceding timestamp-line (and updated as such in the sqlite table)
#         
# How do you drive it? .. Just associate `tinotes.sh` with a shortcut-key.. That's' it!
#      Just press the shortcut-key and you will be presented with Leafpad displaying 
#      a  "title line" at the very top, and on line 2, is a "tinotes timestamp" line.  
#      Type your note below the  timestamp-line, then Save and Exit Leafpad,..
#      NB.. You MUST fully EXIT Leafpad.. the script cannot proceed until you EXIT Leafpad..
#      Leafpad is effectively being used as a Dialog-box with "normal" editing capability.
#      A warning Dialog appears if another instance of this script is currently running.. 
#      (actually, if another ***tinotes** leafpad window is running).
#             
# Caveat: This version is very much "demo-only"... 
#         It works, but has typical "alpha" bugs... 
#         I've presented it here, for anyone who is interested in the general idea.
#             
# dependencies
# ============
#      sqlite3 ,, the notes are stored in a sqlite db.
#      leafpad .. to edit/view the notes (no need to re-invent the wheel)
#       wmctrl .. to detect if a ***tinotes*** leafpad window is currently open.
#      xdotool .. to get the active window's' ID
#     xwininfo .. to get a window's title via it's ID.
#       md5sum .. to check for mods to the presented/added notes data 
#       zenity .. for warning dialog(s)
#          sed .. versatile!
#           wc .. word count? .. line count (here)

############################################################################

function FinalizeNote {
  title="$1"; note="$2"; timeline="$3"; preList="$4"

  # Remove trailing whitespace
  note="${note%"${note##*[![:space:]]}"}"
  # Does this timestamp exist in the  PRE-LIST
  timestamp=${timeline:0:19}
  preCt=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList" |wc -l)
  if [ "$preCt" -eq "0" ] ; then
      sqlite3 "$appdb" "INSERT INTO Tmain (time,title,note) VALUES('$timestamp','$title','$note');"
  elif [ "$preCt" -gt "1" ] ; then
      excod=3
      zenity --error --text "$preCt duplicate timestamps found. \
      \nThis is an 'alpha' problem! \
      \n\n    Exiting with code $excod"
      exit $excod
  else
      # TODO: At it currently stands, it is only known that "something" has changed, 
      #       but not which rows have been effected. (Just update them all, for now.)
      id=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList")
      sqlite3 "$appdb" "UPDATE Tmain SET note='$note' WHERE id='$id';"
      # Remove line from PRE-LIST
      sed -i -e "/^$timestamp.*$/d" "$preList"
  fi
}

############################################################################

  sep="∘" # Field seperator 
  sepmulti="∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘"
  sepfirst="∘∘(write∘new∘notes∘below∘this∘line)∘∘"
  appnam="tinotes"
  appdir="$HOME/.$appnam"
  appdb="$appdir/$appnam.db"
  appsql="$appdir/$appnam.sql"
  apptxt="$appdir/$sep$sep$sep$appnam$sep$sep$sep"
  preList="$appdir/$appnam.pre"; echo -n>"$preList"

  tiwid=0 # Check for a currently running Instance of the "Leafpad"  window...   
  tiwid=$(wmctrl -l |sed -n "s/\([^ ]\+\) \+[^ ]\+ \+[^ ]\+ \*\?$(basename $apptxt)$/\1/p")
  if [ "${tiwid:0:2}" == "0x" ] ; then
      # Warn of the need to finalize an already-running instance of this script
      zenity --warning  --text "You must first finalize a previously opened \n\t 'tinotes' window.\
      \n\n  To activate the window, select 'OK'"
      # 'wmctrl' can only activate via a title
      #   ..and it is case-insensitive and wildcarded!! 
      # so use 'xdotool'
      xdotool windowactivate --sync $(($tiwid))
      exit
  fi

  #################################################################################################################################################
  [ "$clearAllDataAndStartAgain" = "true" ] && [ -d "$appdir" ] && rm -rf  "$appdir" # Typically for TESTING ONLY; Remove all data,and start afresh!  
  #################################################################################################################################################

  # First-time create app's main directory
  [ ! -d "$appdir" ] && mkdir   "$appdir"
  # First-time Create the Tmain table
  [ ! -f "$appdb" ] && sqlite3 "$appdb" "create table Tmain (id INTEGER PRIMARY KEY,time DATE,title TEXT,note TEXT);"

# Get the active-window's title
# =============================
  activeT=$(xwininfo -id "$(xdotool getactivewindow)" |sed -n \
  "2s/^xwininfo: Window id: \(0x[[:xdigit:]]\+\) \x22\(.*\)\x22$/\2/p")

# Does a previous row of the same title already exist?
# ====================================================
  # First, prepare a new/"empty" note entry
    echo "$activeT" >"$apptxt"
    echo -e $(date '+%Y-%m-%d %H:%M:%S' |tr -d '\n')" $sep$appnam$sepfirst\n\n\n">>"$apptxt"

  # Count existing rows for this title
  if [ $(sqlite3 "$appdb" "SELECT COUNT(title) FROM Tmain WHERE title = '$activeT';") -gt 0 ] ; then
      # Previous notes FOUND for this window title
      # Make a list of timestamps to match-off against any user mods 
      sqlite3 "$appdb" "SELECT time,id FROM Tmain WHERE title='$activeT';" >"$preList"

      # Build and Run the query to construct the "timeline"
      echo -e ".separator "$sep"\n\
      SELECT time||' $sep$appnam$sepmulti','\n\n'||note||'\n' FROM Tmain WHERE title='$activeT' order by time desc;">"$appsql"
      sqlite3 "$appdb" <"$appsql">>"$apptxt"
  fi
  # Present the notes to the user (get the  "before" md5sum, to compare with user's access/mods)  
  md5bef=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
  leafpad "$apptxt" # The script waits for the user to close "leafpad"
  md5aft=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
  # Check for any modifications to the notes
  if [ "$md5bef" == "$md5aft" ] ; then
      # No changes have been made.
      exit 0
  fi
  # The notes have been modified. Commit the changes!
  # It's time to analyze the changes, and tidy up.
  #   Remove leading and trailing blank lines (per timestamp).
  #   Delete rows for which the timestamp has been removed.
  #   Update the table for all the remaining rows.
  note=""
  lnCt=0
  while read line ; do
      lnCt=$((lnCt+1))
      [ "$lnCt" -eq "1" ] && continue  # The first line is a throw-away copy of the "title"
      # Find timeline. Any leading data is lost. (It shouldn't be there... common-sense!)
      if [[ "$line" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}\ ∘.*∘$ ]] ; then
          # FOUND timeline
          if [ "$note" != "" ] ; then
              FinalizeNote "$activeT" "$note" "$timeline" "$preList"
          fi
          note=""
          timeline=$line
      elif [ "$line" = "" ] ; then
          if [ "$note" != "" ] ; then
              note="$note$line"$'\n' # append this blank line
          fi
      else
          note="$note$line"$'\n' # append this non-blank line
      fi 
  done <"$apptxt"
  #
  if [ "$note" != "" ] ; then
      FinalizeNote "$activeT" "$note" "$timeline" "$preList"
  fi
  # Delete rows for timestamps still in the PRE-LIST
  while read line ; do
      eval $(echo "$line" |sed -n "s/.*|\([0-9]\+\)$/id=\1/p")
      sqlite3 "$appdb" "DELETE FROM Tmain WHERE id='$id';"
  done <"$preList"

exit 

############################################################################
1
ответ дан 25 May 2018 в 23:45
  • 1
    Вы должны принять это как ответ, это фантастика! И спасибо за объяснение, а не только за сообщение кучки непрозрачных команд. – Stefano Palazzo♦ 5 January 2011 в 01:14

Ну, я снова нахожусь на кривой обучения ... (поздние ночи и много кофе).

Конечным результатом является умеренно используемый bash-скрипт (с использованием sqlite db / table), который делает то, что я был после ... ... т.е. Создает группировку заметок, основанных на названиях окон ...

Это работает .. но это определенно «альфа» ..

Итак, у меня есть мое домашнее приложение ! ... Я размещаю его здесь для всех, кто интересуется «смотри-смотри» ...

Вот он:

#!/bin/bash clearAllDataAndStartAgain="false" # Name: tinotes (Title Notes) # # What does it do? ... Aside from giving me a great opportunity to learn # more about bash (and sqlite, which I had previously barely touched).. not much ;) # Actually, it allows you to keep notes, grouped by window title. # The notes are kept in an sqlite database. # Each timestamped note-"event" is stored in a row of the main (only) table. # You can consolidate notes in a semi ad-hoc manner... # Notes are presented to you in a single editable text file (in Leafpad). # You must keep at least one "tinotes" timestamp-line at the top of the text... # All lines above this topmost timestamp-line are ignored, # including the "title", which is presented upon each viewing. # If you remove any/all other "timestamp line(s)", those particular rows are # deleted from the sqlite table, and the text which remains is associated with # the immediately preceding timestamp-line (and updated as such in the sqlite table) # # How do you drive it? .. Just associate `tinotes.sh` with a shortcut-key.. That's' it! # Just press the shortcut-key and you will be presented with Leafpad displaying # a "title line" at the very top, and on line 2, is a "tinotes timestamp" line. # Type your note below the timestamp-line, then Save and Exit Leafpad,.. # NB.. You MUST fully EXIT Leafpad.. the script cannot proceed until you EXIT Leafpad.. # Leafpad is effectively being used as a Dialog-box with "normal" editing capability. # A warning Dialog appears if another instance of this script is currently running.. # (actually, if another ***tinotes** leafpad window is running). # # Caveat: This version is very much "demo-only"... # It works, but has typical "alpha" bugs... # I've presented it here, for anyone who is interested in the general idea. # # dependencies # ============ # sqlite3 ,, the notes are stored in a sqlite db. # leafpad .. to edit/view the notes (no need to re-invent the wheel) # wmctrl .. to detect if a ***tinotes*** leafpad window is currently open. # xdotool .. to get the active window's' ID # xwininfo .. to get a window's title via it's ID. # md5sum .. to check for mods to the presented/added notes data # zenity .. for warning dialog(s) # sed .. versatile! # wc .. word count? .. line count (here) ############################################################################ function FinalizeNote { title="$1"; note="$2"; timeline="$3"; preList="$4" # Remove trailing whitespace note="${note%"${note##*[![:space:]]}"}" # Does this timestamp exist in the PRE-LIST timestamp=${timeline:0:19} preCt=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList" |wc -l) if [ "$preCt" -eq "0" ] ; then sqlite3 "$appdb" "INSERT INTO Tmain (time,title,note) VALUES('$timestamp','$title','$note');" elif [ "$preCt" -gt "1" ] ; then excod=3 zenity --error --text "$preCt duplicate timestamps found. \ \nThis is an 'alpha' problem! \ \n\n Exiting with code $excod" exit $excod else # TODO: At it currently stands, it is only known that "something" has changed, # but not which rows have been effected. (Just update them all, for now.) id=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList") sqlite3 "$appdb" "UPDATE Tmain SET note='$note' WHERE id='$id';" # Remove line from PRE-LIST sed -i -e "/^$timestamp.*$/d" "$preList" fi } ############################################################################ sep="∘" # Field seperator sepmulti="∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘" sepfirst="∘∘(write∘new∘notes∘below∘this∘line)∘∘" appnam="tinotes" appdir="$HOME/.$appnam" appdb="$appdir/$appnam.db" appsql="$appdir/$appnam.sql" apptxt="$appdir/$sep$sep$sep$appnam$sep$sep$sep" preList="$appdir/$appnam.pre"; echo -n>"$preList" tiwid=0 # Check for a currently running Instance of the "Leafpad" window... tiwid=$(wmctrl -l |sed -n "s/\([^ ]\+\) \+[^ ]\+ \+[^ ]\+ \*\?$(basename $apptxt)$/\1/p") if [ "${tiwid:0:2}" == "0x" ] ; then # Warn of the need to finalize an already-running instance of this script zenity --warning --text "You must first finalize a previously opened \n\t 'tinotes' window.\ \n\n To activate the window, select 'OK'" # 'wmctrl' can only activate via a title # ..and it is case-insensitive and wildcarded!! # so use 'xdotool' xdotool windowactivate --sync $(($tiwid)) exit fi ################################################################################################################################################# [ "$clearAllDataAndStartAgain" = "true" ] && [ -d "$appdir" ] && rm -rf "$appdir" # Typically for TESTING ONLY; Remove all data,and start afresh! ################################################################################################################################################# # First-time create app's main directory [ ! -d "$appdir" ] && mkdir "$appdir" # First-time Create the Tmain table [ ! -f "$appdb" ] && sqlite3 "$appdb" "create table Tmain (id INTEGER PRIMARY KEY,time DATE,title TEXT,note TEXT);" # Get the active-window's title # ============================= activeT=$(xwininfo -id "$(xdotool getactivewindow)" |sed -n \ "2s/^xwininfo: Window id: \(0x[[:xdigit:]]\+\) \x22\(.*\)\x22$/\2/p") # Does a previous row of the same title already exist? # ==================================================== # First, prepare a new/"empty" note entry echo "$activeT" >"$apptxt" echo -e $(date '+%Y-%m-%d %H:%M:%S' |tr -d '\n')" $sep$appnam$sepfirst\n\n\n">>"$apptxt" # Count existing rows for this title if [ $(sqlite3 "$appdb" "SELECT COUNT(title) FROM Tmain WHERE title = '$activeT';") -gt 0 ] ; then # Previous notes FOUND for this window title # Make a list of timestamps to match-off against any user mods sqlite3 "$appdb" "SELECT time,id FROM Tmain WHERE title='$activeT';" >"$preList" # Build and Run the query to construct the "timeline" echo -e ".separator "$sep"\n\ SELECT time||' $sep$appnam$sepmulti','\n\n'||note||'\n' FROM Tmain WHERE title='$activeT' order by time desc;">"$appsql" sqlite3 "$appdb" <"$appsql">>"$apptxt" fi # Present the notes to the user (get the "before" md5sum, to compare with user's access/mods) md5bef=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/") leafpad "$apptxt" # The script waits for the user to close "leafpad" md5aft=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/") # Check for any modifications to the notes if [ "$md5bef" == "$md5aft" ] ; then # No changes have been made. exit 0 fi # The notes have been modified. Commit the changes! # It's time to analyze the changes, and tidy up. # Remove leading and trailing blank lines (per timestamp). # Delete rows for which the timestamp has been removed. # Update the table for all the remaining rows. note="" lnCt=0 while read line ; do lnCt=$((lnCt+1)) [ "$lnCt" -eq "1" ] && continue # The first line is a throw-away copy of the "title" # Find timeline. Any leading data is lost. (It shouldn't be there... common-sense!) if [[ "$line" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}\ ∘.*∘$ ]] ; then # FOUND timeline if [ "$note" != "" ] ; then FinalizeNote "$activeT" "$note" "$timeline" "$preList" fi note="" timeline=$line elif [ "$line" = "" ] ; then if [ "$note" != "" ] ; then note="$note$line"$'\n' # append this blank line fi else note="$note$line"$'\n' # append this non-blank line fi done <"$apptxt" # if [ "$note" != "" ] ; then FinalizeNote "$activeT" "$note" "$timeline" "$preList" fi # Delete rows for timestamps still in the PRE-LIST while read line ; do eval $(echo "$line" |sed -n "s/.*|\([0-9]\+\)$/id=\1/p") sqlite3 "$appdb" "DELETE FROM Tmain WHERE id='$id';" done <"$preList" exit ############################################################################
1
ответ дан 25 July 2018 в 22:41

Ну, я снова нахожусь на кривой обучения ... (поздние ночи и много кофе).

Конечным результатом является умеренно используемый bash-скрипт (с использованием sqlite db / table), который делает то, что я был после ... ... т.е. Создает группировку заметок, основанных на названиях окон ...

Это работает .. но это определенно «альфа» ..

Итак, у меня есть мое домашнее приложение ! ... Я размещаю его здесь для всех, кто интересуется «смотри-смотри» ...

Вот он:

#!/bin/bash clearAllDataAndStartAgain="false" # Name: tinotes (Title Notes) # # What does it do? ... Aside from giving me a great opportunity to learn # more about bash (and sqlite, which I had previously barely touched).. not much ;) # Actually, it allows you to keep notes, grouped by window title. # The notes are kept in an sqlite database. # Each timestamped note-"event" is stored in a row of the main (only) table. # You can consolidate notes in a semi ad-hoc manner... # Notes are presented to you in a single editable text file (in Leafpad). # You must keep at least one "tinotes" timestamp-line at the top of the text... # All lines above this topmost timestamp-line are ignored, # including the "title", which is presented upon each viewing. # If you remove any/all other "timestamp line(s)", those particular rows are # deleted from the sqlite table, and the text which remains is associated with # the immediately preceding timestamp-line (and updated as such in the sqlite table) # # How do you drive it? .. Just associate `tinotes.sh` with a shortcut-key.. That's' it! # Just press the shortcut-key and you will be presented with Leafpad displaying # a "title line" at the very top, and on line 2, is a "tinotes timestamp" line. # Type your note below the timestamp-line, then Save and Exit Leafpad,.. # NB.. You MUST fully EXIT Leafpad.. the script cannot proceed until you EXIT Leafpad.. # Leafpad is effectively being used as a Dialog-box with "normal" editing capability. # A warning Dialog appears if another instance of this script is currently running.. # (actually, if another ***tinotes** leafpad window is running). # # Caveat: This version is very much "demo-only"... # It works, but has typical "alpha" bugs... # I've presented it here, for anyone who is interested in the general idea. # # dependencies # ============ # sqlite3 ,, the notes are stored in a sqlite db. # leafpad .. to edit/view the notes (no need to re-invent the wheel) # wmctrl .. to detect if a ***tinotes*** leafpad window is currently open. # xdotool .. to get the active window's' ID # xwininfo .. to get a window's title via it's ID. # md5sum .. to check for mods to the presented/added notes data # zenity .. for warning dialog(s) # sed .. versatile! # wc .. word count? .. line count (here) ############################################################################ function FinalizeNote { title="$1"; note="$2"; timeline="$3"; preList="$4" # Remove trailing whitespace note="${note%"${note##*[![:space:]]}"}" # Does this timestamp exist in the PRE-LIST timestamp=${timeline:0:19} preCt=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList" |wc -l) if [ "$preCt" -eq "0" ] ; then sqlite3 "$appdb" "INSERT INTO Tmain (time,title,note) VALUES('$timestamp','$title','$note');" elif [ "$preCt" -gt "1" ] ; then excod=3 zenity --error --text "$preCt duplicate timestamps found. \ \nThis is an 'alpha' problem! \ \n\n Exiting with code $excod" exit $excod else # TODO: At it currently stands, it is only known that "something" has changed, # but not which rows have been effected. (Just update them all, for now.) id=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList") sqlite3 "$appdb" "UPDATE Tmain SET note='$note' WHERE id='$id';" # Remove line from PRE-LIST sed -i -e "/^$timestamp.*$/d" "$preList" fi } ############################################################################ sep="∘" # Field seperator sepmulti="∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘" sepfirst="∘∘(write∘new∘notes∘below∘this∘line)∘∘" appnam="tinotes" appdir="$HOME/.$appnam" appdb="$appdir/$appnam.db" appsql="$appdir/$appnam.sql" apptxt="$appdir/$sep$sep$sep$appnam$sep$sep$sep" preList="$appdir/$appnam.pre"; echo -n>"$preList" tiwid=0 # Check for a currently running Instance of the "Leafpad" window... tiwid=$(wmctrl -l |sed -n "s/\([^ ]\+\) \+[^ ]\+ \+[^ ]\+ \*\?$(basename $apptxt)$/\1/p") if [ "${tiwid:0:2}" == "0x" ] ; then # Warn of the need to finalize an already-running instance of this script zenity --warning --text "You must first finalize a previously opened \n\t 'tinotes' window.\ \n\n To activate the window, select 'OK'" # 'wmctrl' can only activate via a title # ..and it is case-insensitive and wildcarded!! # so use 'xdotool' xdotool windowactivate --sync $(($tiwid)) exit fi ################################################################################################################################################# [ "$clearAllDataAndStartAgain" = "true" ] && [ -d "$appdir" ] && rm -rf "$appdir" # Typically for TESTING ONLY; Remove all data,and start afresh! ################################################################################################################################################# # First-time create app's main directory [ ! -d "$appdir" ] && mkdir "$appdir" # First-time Create the Tmain table [ ! -f "$appdb" ] && sqlite3 "$appdb" "create table Tmain (id INTEGER PRIMARY KEY,time DATE,title TEXT,note TEXT);" # Get the active-window's title # ============================= activeT=$(xwininfo -id "$(xdotool getactivewindow)" |sed -n \ "2s/^xwininfo: Window id: \(0x[[:xdigit:]]\+\) \x22\(.*\)\x22$/\2/p") # Does a previous row of the same title already exist? # ==================================================== # First, prepare a new/"empty" note entry echo "$activeT" >"$apptxt" echo -e $(date '+%Y-%m-%d %H:%M:%S' |tr -d '\n')" $sep$appnam$sepfirst\n\n\n">>"$apptxt" # Count existing rows for this title if [ $(sqlite3 "$appdb" "SELECT COUNT(title) FROM Tmain WHERE title = '$activeT';") -gt 0 ] ; then # Previous notes FOUND for this window title # Make a list of timestamps to match-off against any user mods sqlite3 "$appdb" "SELECT time,id FROM Tmain WHERE title='$activeT';" >"$preList" # Build and Run the query to construct the "timeline" echo -e ".separator "$sep"\n\ SELECT time||' $sep$appnam$sepmulti','\n\n'||note||'\n' FROM Tmain WHERE title='$activeT' order by time desc;">"$appsql" sqlite3 "$appdb" <"$appsql">>"$apptxt" fi # Present the notes to the user (get the "before" md5sum, to compare with user's access/mods) md5bef=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/") leafpad "$apptxt" # The script waits for the user to close "leafpad" md5aft=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/") # Check for any modifications to the notes if [ "$md5bef" == "$md5aft" ] ; then # No changes have been made. exit 0 fi # The notes have been modified. Commit the changes! # It's time to analyze the changes, and tidy up. # Remove leading and trailing blank lines (per timestamp). # Delete rows for which the timestamp has been removed. # Update the table for all the remaining rows. note="" lnCt=0 while read line ; do lnCt=$((lnCt+1)) [ "$lnCt" -eq "1" ] && continue # The first line is a throw-away copy of the "title" # Find timeline. Any leading data is lost. (It shouldn't be there... common-sense!) if [[ "$line" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}\ ∘.*∘$ ]] ; then # FOUND timeline if [ "$note" != "" ] ; then FinalizeNote "$activeT" "$note" "$timeline" "$preList" fi note="" timeline=$line elif [ "$line" = "" ] ; then if [ "$note" != "" ] ; then note="$note$line"$'\n' # append this blank line fi else note="$note$line"$'\n' # append this non-blank line fi done <"$apptxt" # if [ "$note" != "" ] ; then FinalizeNote "$activeT" "$note" "$timeline" "$preList" fi # Delete rows for timestamps still in the PRE-LIST while read line ; do eval $(echo "$line" |sed -n "s/.*|\([0-9]\+\)$/id=\1/p") sqlite3 "$appdb" "DELETE FROM Tmain WHERE id='$id';" done <"$preList" exit ############################################################################
1
ответ дан 2 August 2018 в 04:07

Ну, я снова учился на учебе ... (поздние ночи и много кофе).

Конечным результатом является умеренно используемый bash-скрипт (с использованием sqlite db / table), который делает то, что я был после ... ... т.е. Создает группировку заметок на основе оконных заголовков ...

Это работает .. но это определенно «альфа» ..

Итак, у меня есть мое домашнее приложение ! ... Я размещаю его здесь для всех, кто интересуется «смотри-смотри» ...

Вот он:


#!/bin/bash

clearAllDataAndStartAgain="false"

# Name: tinotes (Title Notes)
# 
# What does it do? ... Aside from giving me a great opportunity to learn
#      more about bash (and sqlite, which I had previously barely touched).. not much ;)
#      Actually, it allows you to keep notes, grouped by window title.
#      The notes are kept in an sqlite database. 
#      Each timestamped note-"event" is stored in a row of the main (only) table.
#      You can consolidate notes in a semi ad-hoc manner... 
#      Notes are presented to you in a single editable text file (in Leafpad).  
#      You must keep at least one "tinotes" timestamp-line at the top of the text...
#      All lines above this topmost timestamp-line are ignored,
#      including the "title", which is presented upon each viewing.
#      If you remove any/all other "timestamp line(s)", those particular rows are 
#      deleted from the sqlite table, and the text which remains is associated with
#      the immediately preceding timestamp-line (and updated as such in the sqlite table)
#         
# How do you drive it? .. Just associate `tinotes.sh` with a shortcut-key.. That's' it!
#      Just press the shortcut-key and you will be presented with Leafpad displaying 
#      a  "title line" at the very top, and on line 2, is a "tinotes timestamp" line.  
#      Type your note below the  timestamp-line, then Save and Exit Leafpad,..
#      NB.. You MUST fully EXIT Leafpad.. the script cannot proceed until you EXIT Leafpad..
#      Leafpad is effectively being used as a Dialog-box with "normal" editing capability.
#      A warning Dialog appears if another instance of this script is currently running.. 
#      (actually, if another ***tinotes** leafpad window is running).
#             
# Caveat: This version is very much "demo-only"... 
#         It works, but has typical "alpha" bugs... 
#         I've presented it here, for anyone who is interested in the general idea.
#             
# dependencies
# ============
#      sqlite3 ,, the notes are stored in a sqlite db.
#      leafpad .. to edit/view the notes (no need to re-invent the wheel)
#       wmctrl .. to detect if a ***tinotes*** leafpad window is currently open.
#      xdotool .. to get the active window's' ID
#     xwininfo .. to get a window's title via it's ID.
#       md5sum .. to check for mods to the presented/added notes data 
#       zenity .. for warning dialog(s)
#          sed .. versatile!
#           wc .. word count? .. line count (here)

############################################################################

function FinalizeNote {
  title="$1"; note="$2"; timeline="$3"; preList="$4"

  # Remove trailing whitespace
  note="${note%"${note##*[![:space:]]}"}"
  # Does this timestamp exist in the  PRE-LIST
  timestamp=${timeline:0:19}
  preCt=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList" |wc -l)
  if [ "$preCt" -eq "0" ] ; then
      sqlite3 "$appdb" "INSERT INTO Tmain (time,title,note) VALUES('$timestamp','$title','$note');"
  elif [ "$preCt" -gt "1" ] ; then
      excod=3
      zenity --error --text "$preCt duplicate timestamps found. \
      \nThis is an 'alpha' problem! \
      \n\n    Exiting with code $excod"
      exit $excod
  else
      # TODO: At it currently stands, it is only known that "something" has changed, 
      #       but not which rows have been effected. (Just update them all, for now.)
      id=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList")
      sqlite3 "$appdb" "UPDATE Tmain SET note='$note' WHERE id='$id';"
      # Remove line from PRE-LIST
      sed -i -e "/^$timestamp.*$/d" "$preList"
  fi
}

############################################################################

  sep="∘" # Field seperator 
  sepmulti="∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘"
  sepfirst="∘∘(write∘new∘notes∘below∘this∘line)∘∘"
  appnam="tinotes"
  appdir="$HOME/.$appnam"
  appdb="$appdir/$appnam.db"
  appsql="$appdir/$appnam.sql"
  apptxt="$appdir/$sep$sep$sep$appnam$sep$sep$sep"
  preList="$appdir/$appnam.pre"; echo -n>"$preList"

  tiwid=0 # Check for a currently running Instance of the "Leafpad"  window...   
  tiwid=$(wmctrl -l |sed -n "s/\([^ ]\+\) \+[^ ]\+ \+[^ ]\+ \*\?$(basename $apptxt)$/\1/p")
  if [ "${tiwid:0:2}" == "0x" ] ; then
      # Warn of the need to finalize an already-running instance of this script
      zenity --warning  --text "You must first finalize a previously opened \n\t 'tinotes' window.\
      \n\n  To activate the window, select 'OK'"
      # 'wmctrl' can only activate via a title
      #   ..and it is case-insensitive and wildcarded!! 
      # so use 'xdotool'
      xdotool windowactivate --sync $(($tiwid))
      exit
  fi

  #################################################################################################################################################
  [ "$clearAllDataAndStartAgain" = "true" ] && [ -d "$appdir" ] && rm -rf  "$appdir" # Typically for TESTING ONLY; Remove all data,and start afresh!  
  #################################################################################################################################################

  # First-time create app's main directory
  [ ! -d "$appdir" ] && mkdir   "$appdir"
  # First-time Create the Tmain table
  [ ! -f "$appdb" ] && sqlite3 "$appdb" "create table Tmain (id INTEGER PRIMARY KEY,time DATE,title TEXT,note TEXT);"

# Get the active-window's title
# =============================
  activeT=$(xwininfo -id "$(xdotool getactivewindow)" |sed -n \
  "2s/^xwininfo: Window id: \(0x[[:xdigit:]]\+\) \x22\(.*\)\x22$/\2/p")

# Does a previous row of the same title already exist?
# ====================================================
  # First, prepare a new/"empty" note entry
    echo "$activeT" >"$apptxt"
    echo -e $(date '+%Y-%m-%d %H:%M:%S' |tr -d '\n')" $sep$appnam$sepfirst\n\n\n">>"$apptxt"

  # Count existing rows for this title
  if [ $(sqlite3 "$appdb" "SELECT COUNT(title) FROM Tmain WHERE title = '$activeT';") -gt 0 ] ; then
      # Previous notes FOUND for this window title
      # Make a list of timestamps to match-off against any user mods 
      sqlite3 "$appdb" "SELECT time,id FROM Tmain WHERE title='$activeT';" >"$preList"

      # Build and Run the query to construct the "timeline"
      echo -e ".separator "$sep"\n\
      SELECT time||' $sep$appnam$sepmulti','\n\n'||note||'\n' FROM Tmain WHERE title='$activeT' order by time desc;">"$appsql"
      sqlite3 "$appdb" <"$appsql">>"$apptxt"
  fi
  # Present the notes to the user (get the  "before" md5sum, to compare with user's access/mods)  
  md5bef=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
  leafpad "$apptxt" # The script waits for the user to close "leafpad"
  md5aft=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
  # Check for any modifications to the notes
  if [ "$md5bef" == "$md5aft" ] ; then
      # No changes have been made.
      exit 0
  fi
  # The notes have been modified. Commit the changes!
  # It's time to analyze the changes, and tidy up.
  #   Remove leading and trailing blank lines (per timestamp).
  #   Delete rows for which the timestamp has been removed.
  #   Update the table for all the remaining rows.
  note=""
  lnCt=0
  while read line ; do
      lnCt=$((lnCt+1))
      [ "$lnCt" -eq "1" ] && continue  # The first line is a throw-away copy of the "title"
      # Find timeline. Any leading data is lost. (It shouldn't be there... common-sense!)
      if [[ "$line" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}\ ∘.*∘$ ]] ; then
          # FOUND timeline
          if [ "$note" != "" ] ; then
              FinalizeNote "$activeT" "$note" "$timeline" "$preList"
          fi
          note=""
          timeline=$line
      elif [ "$line" = "" ] ; then
          if [ "$note" != "" ] ; then
              note="$note$line"$'\n' # append this blank line
          fi
      else
          note="$note$line"$'\n' # append this non-blank line
      fi 
  done <"$apptxt"
  #
  if [ "$note" != "" ] ; then
      FinalizeNote "$activeT" "$note" "$timeline" "$preList"
  fi
  # Delete rows for timestamps still in the PRE-LIST
  while read line ; do
      eval $(echo "$line" |sed -n "s/.*|\([0-9]\+\)$/id=\1/p")
      sqlite3 "$appdb" "DELETE FROM Tmain WHERE id='$id';"
  done <"$preList"

exit 

############################################################################
1
ответ дан 4 August 2018 в 20:10

Ну, я снова учился на учебе ... (поздние ночи и много кофе).

Конечным результатом является умеренно используемый bash-скрипт (с использованием sqlite db / table), который делает то, что я был после ... ... т.е. Создает группировку заметок на основе оконных заголовков ...

Это работает .. но это определенно «альфа» ..

Итак, у меня есть мое домашнее приложение ! ... Я размещаю его здесь для всех, кто интересуется «смотри-смотри» ...

Вот он:


#!/bin/bash

clearAllDataAndStartAgain="false"

# Name: tinotes (Title Notes)
# 
# What does it do? ... Aside from giving me a great opportunity to learn
#      more about bash (and sqlite, which I had previously barely touched).. not much ;)
#      Actually, it allows you to keep notes, grouped by window title.
#      The notes are kept in an sqlite database. 
#      Each timestamped note-"event" is stored in a row of the main (only) table.
#      You can consolidate notes in a semi ad-hoc manner... 
#      Notes are presented to you in a single editable text file (in Leafpad).  
#      You must keep at least one "tinotes" timestamp-line at the top of the text...
#      All lines above this topmost timestamp-line are ignored,
#      including the "title", which is presented upon each viewing.
#      If you remove any/all other "timestamp line(s)", those particular rows are 
#      deleted from the sqlite table, and the text which remains is associated with
#      the immediately preceding timestamp-line (and updated as such in the sqlite table)
#         
# How do you drive it? .. Just associate `tinotes.sh` with a shortcut-key.. That's' it!
#      Just press the shortcut-key and you will be presented with Leafpad displaying 
#      a  "title line" at the very top, and on line 2, is a "tinotes timestamp" line.  
#      Type your note below the  timestamp-line, then Save and Exit Leafpad,..
#      NB.. You MUST fully EXIT Leafpad.. the script cannot proceed until you EXIT Leafpad..
#      Leafpad is effectively being used as a Dialog-box with "normal" editing capability.
#      A warning Dialog appears if another instance of this script is currently running.. 
#      (actually, if another ***tinotes** leafpad window is running).
#             
# Caveat: This version is very much "demo-only"... 
#         It works, but has typical "alpha" bugs... 
#         I've presented it here, for anyone who is interested in the general idea.
#             
# dependencies
# ============
#      sqlite3 ,, the notes are stored in a sqlite db.
#      leafpad .. to edit/view the notes (no need to re-invent the wheel)
#       wmctrl .. to detect if a ***tinotes*** leafpad window is currently open.
#      xdotool .. to get the active window's' ID
#     xwininfo .. to get a window's title via it's ID.
#       md5sum .. to check for mods to the presented/added notes data 
#       zenity .. for warning dialog(s)
#          sed .. versatile!
#           wc .. word count? .. line count (here)

############################################################################

function FinalizeNote {
  title="$1"; note="$2"; timeline="$3"; preList="$4"

  # Remove trailing whitespace
  note="${note%"${note##*[![:space:]]}"}"
  # Does this timestamp exist in the  PRE-LIST
  timestamp=${timeline:0:19}
  preCt=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList" |wc -l)
  if [ "$preCt" -eq "0" ] ; then
      sqlite3 "$appdb" "INSERT INTO Tmain (time,title,note) VALUES('$timestamp','$title','$note');"
  elif [ "$preCt" -gt "1" ] ; then
      excod=3
      zenity --error --text "$preCt duplicate timestamps found. \
      \nThis is an 'alpha' problem! \
      \n\n    Exiting with code $excod"
      exit $excod
  else
      # TODO: At it currently stands, it is only known that "something" has changed, 
      #       but not which rows have been effected. (Just update them all, for now.)
      id=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList")
      sqlite3 "$appdb" "UPDATE Tmain SET note='$note' WHERE id='$id';"
      # Remove line from PRE-LIST
      sed -i -e "/^$timestamp.*$/d" "$preList"
  fi
}

############################################################################

  sep="∘" # Field seperator 
  sepmulti="∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘"
  sepfirst="∘∘(write∘new∘notes∘below∘this∘line)∘∘"
  appnam="tinotes"
  appdir="$HOME/.$appnam"
  appdb="$appdir/$appnam.db"
  appsql="$appdir/$appnam.sql"
  apptxt="$appdir/$sep$sep$sep$appnam$sep$sep$sep"
  preList="$appdir/$appnam.pre"; echo -n>"$preList"

  tiwid=0 # Check for a currently running Instance of the "Leafpad"  window...   
  tiwid=$(wmctrl -l |sed -n "s/\([^ ]\+\) \+[^ ]\+ \+[^ ]\+ \*\?$(basename $apptxt)$/\1/p")
  if [ "${tiwid:0:2}" == "0x" ] ; then
      # Warn of the need to finalize an already-running instance of this script
      zenity --warning  --text "You must first finalize a previously opened \n\t 'tinotes' window.\
      \n\n  To activate the window, select 'OK'"
      # 'wmctrl' can only activate via a title
      #   ..and it is case-insensitive and wildcarded!! 
      # so use 'xdotool'
      xdotool windowactivate --sync $(($tiwid))
      exit
  fi

  #################################################################################################################################################
  [ "$clearAllDataAndStartAgain" = "true" ] && [ -d "$appdir" ] && rm -rf  "$appdir" # Typically for TESTING ONLY; Remove all data,and start afresh!  
  #################################################################################################################################################

  # First-time create app's main directory
  [ ! -d "$appdir" ] && mkdir   "$appdir"
  # First-time Create the Tmain table
  [ ! -f "$appdb" ] && sqlite3 "$appdb" "create table Tmain (id INTEGER PRIMARY KEY,time DATE,title TEXT,note TEXT);"

# Get the active-window's title
# =============================
  activeT=$(xwininfo -id "$(xdotool getactivewindow)" |sed -n \
  "2s/^xwininfo: Window id: \(0x[[:xdigit:]]\+\) \x22\(.*\)\x22$/\2/p")

# Does a previous row of the same title already exist?
# ====================================================
  # First, prepare a new/"empty" note entry
    echo "$activeT" >"$apptxt"
    echo -e $(date '+%Y-%m-%d %H:%M:%S' |tr -d '\n')" $sep$appnam$sepfirst\n\n\n">>"$apptxt"

  # Count existing rows for this title
  if [ $(sqlite3 "$appdb" "SELECT COUNT(title) FROM Tmain WHERE title = '$activeT';") -gt 0 ] ; then
      # Previous notes FOUND for this window title
      # Make a list of timestamps to match-off against any user mods 
      sqlite3 "$appdb" "SELECT time,id FROM Tmain WHERE title='$activeT';" >"$preList"

      # Build and Run the query to construct the "timeline"
      echo -e ".separator "$sep"\n\
      SELECT time||' $sep$appnam$sepmulti','\n\n'||note||'\n' FROM Tmain WHERE title='$activeT' order by time desc;">"$appsql"
      sqlite3 "$appdb" <"$appsql">>"$apptxt"
  fi
  # Present the notes to the user (get the  "before" md5sum, to compare with user's access/mods)  
  md5bef=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
  leafpad "$apptxt" # The script waits for the user to close "leafpad"
  md5aft=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
  # Check for any modifications to the notes
  if [ "$md5bef" == "$md5aft" ] ; then
      # No changes have been made.
      exit 0
  fi
  # The notes have been modified. Commit the changes!
  # It's time to analyze the changes, and tidy up.
  #   Remove leading and trailing blank lines (per timestamp).
  #   Delete rows for which the timestamp has been removed.
  #   Update the table for all the remaining rows.
  note=""
  lnCt=0
  while read line ; do
      lnCt=$((lnCt+1))
      [ "$lnCt" -eq "1" ] && continue  # The first line is a throw-away copy of the "title"
      # Find timeline. Any leading data is lost. (It shouldn't be there... common-sense!)
      if [[ "$line" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}\ ∘.*∘$ ]] ; then
          # FOUND timeline
          if [ "$note" != "" ] ; then
              FinalizeNote "$activeT" "$note" "$timeline" "$preList"
          fi
          note=""
          timeline=$line
      elif [ "$line" = "" ] ; then
          if [ "$note" != "" ] ; then
              note="$note$line"$'\n' # append this blank line
          fi
      else
          note="$note$line"$'\n' # append this non-blank line
      fi 
  done <"$apptxt"
  #
  if [ "$note" != "" ] ; then
      FinalizeNote "$activeT" "$note" "$timeline" "$preList"
  fi
  # Delete rows for timestamps still in the PRE-LIST
  while read line ; do
      eval $(echo "$line" |sed -n "s/.*|\([0-9]\+\)$/id=\1/p")
      sqlite3 "$appdb" "DELETE FROM Tmain WHERE id='$id';"
  done <"$preList"

exit 

############################################################################
1
ответ дан 6 August 2018 в 04:12

Ну, я снова учился на учебе ... (поздние ночи и много кофе).

Конечным результатом является умеренно используемый bash-скрипт (с использованием sqlite db / table), который делает то, что я был после ... ... т.е. Создает группировку заметок на основе оконных заголовков ...

Это работает .. но это определенно «альфа» ..

Итак, у меня есть мое домашнее приложение ! ... Я размещаю его здесь для всех, кто интересуется «смотри-смотри» ...

Вот он:


#!/bin/bash

clearAllDataAndStartAgain="false"

# Name: tinotes (Title Notes)
# 
# What does it do? ... Aside from giving me a great opportunity to learn
#      more about bash (and sqlite, which I had previously barely touched).. not much ;)
#      Actually, it allows you to keep notes, grouped by window title.
#      The notes are kept in an sqlite database. 
#      Each timestamped note-"event" is stored in a row of the main (only) table.
#      You can consolidate notes in a semi ad-hoc manner... 
#      Notes are presented to you in a single editable text file (in Leafpad).  
#      You must keep at least one "tinotes" timestamp-line at the top of the text...
#      All lines above this topmost timestamp-line are ignored,
#      including the "title", which is presented upon each viewing.
#      If you remove any/all other "timestamp line(s)", those particular rows are 
#      deleted from the sqlite table, and the text which remains is associated with
#      the immediately preceding timestamp-line (and updated as such in the sqlite table)
#         
# How do you drive it? .. Just associate `tinotes.sh` with a shortcut-key.. That's' it!
#      Just press the shortcut-key and you will be presented with Leafpad displaying 
#      a  "title line" at the very top, and on line 2, is a "tinotes timestamp" line.  
#      Type your note below the  timestamp-line, then Save and Exit Leafpad,..
#      NB.. You MUST fully EXIT Leafpad.. the script cannot proceed until you EXIT Leafpad..
#      Leafpad is effectively being used as a Dialog-box with "normal" editing capability.
#      A warning Dialog appears if another instance of this script is currently running.. 
#      (actually, if another ***tinotes** leafpad window is running).
#             
# Caveat: This version is very much "demo-only"... 
#         It works, but has typical "alpha" bugs... 
#         I've presented it here, for anyone who is interested in the general idea.
#             
# dependencies
# ============
#      sqlite3 ,, the notes are stored in a sqlite db.
#      leafpad .. to edit/view the notes (no need to re-invent the wheel)
#       wmctrl .. to detect if a ***tinotes*** leafpad window is currently open.
#      xdotool .. to get the active window's' ID
#     xwininfo .. to get a window's title via it's ID.
#       md5sum .. to check for mods to the presented/added notes data 
#       zenity .. for warning dialog(s)
#          sed .. versatile!
#           wc .. word count? .. line count (here)

############################################################################

function FinalizeNote {
  title="$1"; note="$2"; timeline="$3"; preList="$4"

  # Remove trailing whitespace
  note="${note%"${note##*[![:space:]]}"}"
  # Does this timestamp exist in the  PRE-LIST
  timestamp=${timeline:0:19}
  preCt=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList" |wc -l)
  if [ "$preCt" -eq "0" ] ; then
      sqlite3 "$appdb" "INSERT INTO Tmain (time,title,note) VALUES('$timestamp','$title','$note');"
  elif [ "$preCt" -gt "1" ] ; then
      excod=3
      zenity --error --text "$preCt duplicate timestamps found. \
      \nThis is an 'alpha' problem! \
      \n\n    Exiting with code $excod"
      exit $excod
  else
      # TODO: At it currently stands, it is only known that "something" has changed, 
      #       but not which rows have been effected. (Just update them all, for now.)
      id=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList")
      sqlite3 "$appdb" "UPDATE Tmain SET note='$note' WHERE id='$id';"
      # Remove line from PRE-LIST
      sed -i -e "/^$timestamp.*$/d" "$preList"
  fi
}

############################################################################

  sep="∘" # Field seperator 
  sepmulti="∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘"
  sepfirst="∘∘(write∘new∘notes∘below∘this∘line)∘∘"
  appnam="tinotes"
  appdir="$HOME/.$appnam"
  appdb="$appdir/$appnam.db"
  appsql="$appdir/$appnam.sql"
  apptxt="$appdir/$sep$sep$sep$appnam$sep$sep$sep"
  preList="$appdir/$appnam.pre"; echo -n>"$preList"

  tiwid=0 # Check for a currently running Instance of the "Leafpad"  window...   
  tiwid=$(wmctrl -l |sed -n "s/\([^ ]\+\) \+[^ ]\+ \+[^ ]\+ \*\?$(basename $apptxt)$/\1/p")
  if [ "${tiwid:0:2}" == "0x" ] ; then
      # Warn of the need to finalize an already-running instance of this script
      zenity --warning  --text "You must first finalize a previously opened \n\t 'tinotes' window.\
      \n\n  To activate the window, select 'OK'"
      # 'wmctrl' can only activate via a title
      #   ..and it is case-insensitive and wildcarded!! 
      # so use 'xdotool'
      xdotool windowactivate --sync $(($tiwid))
      exit
  fi

  #################################################################################################################################################
  [ "$clearAllDataAndStartAgain" = "true" ] && [ -d "$appdir" ] && rm -rf  "$appdir" # Typically for TESTING ONLY; Remove all data,and start afresh!  
  #################################################################################################################################################

  # First-time create app's main directory
  [ ! -d "$appdir" ] && mkdir   "$appdir"
  # First-time Create the Tmain table
  [ ! -f "$appdb" ] && sqlite3 "$appdb" "create table Tmain (id INTEGER PRIMARY KEY,time DATE,title TEXT,note TEXT);"

# Get the active-window's title
# =============================
  activeT=$(xwininfo -id "$(xdotool getactivewindow)" |sed -n \
  "2s/^xwininfo: Window id: \(0x[[:xdigit:]]\+\) \x22\(.*\)\x22$/\2/p")

# Does a previous row of the same title already exist?
# ====================================================
  # First, prepare a new/"empty" note entry
    echo "$activeT" >"$apptxt"
    echo -e $(date '+%Y-%m-%d %H:%M:%S' |tr -d '\n')" $sep$appnam$sepfirst\n\n\n">>"$apptxt"

  # Count existing rows for this title
  if [ $(sqlite3 "$appdb" "SELECT COUNT(title) FROM Tmain WHERE title = '$activeT';") -gt 0 ] ; then
      # Previous notes FOUND for this window title
      # Make a list of timestamps to match-off against any user mods 
      sqlite3 "$appdb" "SELECT time,id FROM Tmain WHERE title='$activeT';" >"$preList"

      # Build and Run the query to construct the "timeline"
      echo -e ".separator "$sep"\n\
      SELECT time||' $sep$appnam$sepmulti','\n\n'||note||'\n' FROM Tmain WHERE title='$activeT' order by time desc;">"$appsql"
      sqlite3 "$appdb" <"$appsql">>"$apptxt"
  fi
  # Present the notes to the user (get the  "before" md5sum, to compare with user's access/mods)  
  md5bef=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
  leafpad "$apptxt" # The script waits for the user to close "leafpad"
  md5aft=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
  # Check for any modifications to the notes
  if [ "$md5bef" == "$md5aft" ] ; then
      # No changes have been made.
      exit 0
  fi
  # The notes have been modified. Commit the changes!
  # It's time to analyze the changes, and tidy up.
  #   Remove leading and trailing blank lines (per timestamp).
  #   Delete rows for which the timestamp has been removed.
  #   Update the table for all the remaining rows.
  note=""
  lnCt=0
  while read line ; do
      lnCt=$((lnCt+1))
      [ "$lnCt" -eq "1" ] && continue  # The first line is a throw-away copy of the "title"
      # Find timeline. Any leading data is lost. (It shouldn't be there... common-sense!)
      if [[ "$line" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}\ ∘.*∘$ ]] ; then
          # FOUND timeline
          if [ "$note" != "" ] ; then
              FinalizeNote "$activeT" "$note" "$timeline" "$preList"
          fi
          note=""
          timeline=$line
      elif [ "$line" = "" ] ; then
          if [ "$note" != "" ] ; then
              note="$note$line"$'\n' # append this blank line
          fi
      else
          note="$note$line"$'\n' # append this non-blank line
      fi 
  done <"$apptxt"
  #
  if [ "$note" != "" ] ; then
      FinalizeNote "$activeT" "$note" "$timeline" "$preList"
  fi
  # Delete rows for timestamps still in the PRE-LIST
  while read line ; do
      eval $(echo "$line" |sed -n "s/.*|\([0-9]\+\)$/id=\1/p")
      sqlite3 "$appdb" "DELETE FROM Tmain WHERE id='$id';"
  done <"$preList"

exit 

############################################################################
1
ответ дан 10 August 2018 в 10:25

Ну, я снова учился на учебе ... (поздние ночи и много кофе).

Конечным результатом является умеренно используемый bash-скрипт (с использованием sqlite db / table), который делает то, что я был после ... ... т.е. Создает группировку заметок на основе оконных заголовков ...

Это работает .. но это определенно «альфа» ..

Итак, у меня есть мое домашнее приложение ! ... Я размещаю его здесь для всех, кто интересуется «смотри-смотри» ...

Вот он:


#!/bin/bash

clearAllDataAndStartAgain="false"

# Name: tinotes (Title Notes)
# 
# What does it do? ... Aside from giving me a great opportunity to learn
#      more about bash (and sqlite, which I had previously barely touched).. not much ;)
#      Actually, it allows you to keep notes, grouped by window title.
#      The notes are kept in an sqlite database. 
#      Each timestamped note-"event" is stored in a row of the main (only) table.
#      You can consolidate notes in a semi ad-hoc manner... 
#      Notes are presented to you in a single editable text file (in Leafpad).  
#      You must keep at least one "tinotes" timestamp-line at the top of the text...
#      All lines above this topmost timestamp-line are ignored,
#      including the "title", which is presented upon each viewing.
#      If you remove any/all other "timestamp line(s)", those particular rows are 
#      deleted from the sqlite table, and the text which remains is associated with
#      the immediately preceding timestamp-line (and updated as such in the sqlite table)
#         
# How do you drive it? .. Just associate `tinotes.sh` with a shortcut-key.. That's' it!
#      Just press the shortcut-key and you will be presented with Leafpad displaying 
#      a  "title line" at the very top, and on line 2, is a "tinotes timestamp" line.  
#      Type your note below the  timestamp-line, then Save and Exit Leafpad,..
#      NB.. You MUST fully EXIT Leafpad.. the script cannot proceed until you EXIT Leafpad..
#      Leafpad is effectively being used as a Dialog-box with "normal" editing capability.
#      A warning Dialog appears if another instance of this script is currently running.. 
#      (actually, if another ***tinotes** leafpad window is running).
#             
# Caveat: This version is very much "demo-only"... 
#         It works, but has typical "alpha" bugs... 
#         I've presented it here, for anyone who is interested in the general idea.
#             
# dependencies
# ============
#      sqlite3 ,, the notes are stored in a sqlite db.
#      leafpad .. to edit/view the notes (no need to re-invent the wheel)
#       wmctrl .. to detect if a ***tinotes*** leafpad window is currently open.
#      xdotool .. to get the active window's' ID
#     xwininfo .. to get a window's title via it's ID.
#       md5sum .. to check for mods to the presented/added notes data 
#       zenity .. for warning dialog(s)
#          sed .. versatile!
#           wc .. word count? .. line count (here)

############################################################################

function FinalizeNote {
  title="$1"; note="$2"; timeline="$3"; preList="$4"

  # Remove trailing whitespace
  note="${note%"${note##*[![:space:]]}"}"
  # Does this timestamp exist in the  PRE-LIST
  timestamp=${timeline:0:19}
  preCt=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList" |wc -l)
  if [ "$preCt" -eq "0" ] ; then
      sqlite3 "$appdb" "INSERT INTO Tmain (time,title,note) VALUES('$timestamp','$title','$note');"
  elif [ "$preCt" -gt "1" ] ; then
      excod=3
      zenity --error --text "$preCt duplicate timestamps found. \
      \nThis is an 'alpha' problem! \
      \n\n    Exiting with code $excod"
      exit $excod
  else
      # TODO: At it currently stands, it is only known that "something" has changed, 
      #       but not which rows have been effected. (Just update them all, for now.)
      id=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList")
      sqlite3 "$appdb" "UPDATE Tmain SET note='$note' WHERE id='$id';"
      # Remove line from PRE-LIST
      sed -i -e "/^$timestamp.*$/d" "$preList"
  fi
}

############################################################################

  sep="∘" # Field seperator 
  sepmulti="∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘"
  sepfirst="∘∘(write∘new∘notes∘below∘this∘line)∘∘"
  appnam="tinotes"
  appdir="$HOME/.$appnam"
  appdb="$appdir/$appnam.db"
  appsql="$appdir/$appnam.sql"
  apptxt="$appdir/$sep$sep$sep$appnam$sep$sep$sep"
  preList="$appdir/$appnam.pre"; echo -n>"$preList"

  tiwid=0 # Check for a currently running Instance of the "Leafpad"  window...   
  tiwid=$(wmctrl -l |sed -n "s/\([^ ]\+\) \+[^ ]\+ \+[^ ]\+ \*\?$(basename $apptxt)$/\1/p")
  if [ "${tiwid:0:2}" == "0x" ] ; then
      # Warn of the need to finalize an already-running instance of this script
      zenity --warning  --text "You must first finalize a previously opened \n\t 'tinotes' window.\
      \n\n  To activate the window, select 'OK'"
      # 'wmctrl' can only activate via a title
      #   ..and it is case-insensitive and wildcarded!! 
      # so use 'xdotool'
      xdotool windowactivate --sync $(($tiwid))
      exit
  fi

  #################################################################################################################################################
  [ "$clearAllDataAndStartAgain" = "true" ] && [ -d "$appdir" ] && rm -rf  "$appdir" # Typically for TESTING ONLY; Remove all data,and start afresh!  
  #################################################################################################################################################

  # First-time create app's main directory
  [ ! -d "$appdir" ] && mkdir   "$appdir"
  # First-time Create the Tmain table
  [ ! -f "$appdb" ] && sqlite3 "$appdb" "create table Tmain (id INTEGER PRIMARY KEY,time DATE,title TEXT,note TEXT);"

# Get the active-window's title
# =============================
  activeT=$(xwininfo -id "$(xdotool getactivewindow)" |sed -n \
  "2s/^xwininfo: Window id: \(0x[[:xdigit:]]\+\) \x22\(.*\)\x22$/\2/p")

# Does a previous row of the same title already exist?
# ====================================================
  # First, prepare a new/"empty" note entry
    echo "$activeT" >"$apptxt"
    echo -e $(date '+%Y-%m-%d %H:%M:%S' |tr -d '\n')" $sep$appnam$sepfirst\n\n\n">>"$apptxt"

  # Count existing rows for this title
  if [ $(sqlite3 "$appdb" "SELECT COUNT(title) FROM Tmain WHERE title = '$activeT';") -gt 0 ] ; then
      # Previous notes FOUND for this window title
      # Make a list of timestamps to match-off against any user mods 
      sqlite3 "$appdb" "SELECT time,id FROM Tmain WHERE title='$activeT';" >"$preList"

      # Build and Run the query to construct the "timeline"
      echo -e ".separator "$sep"\n\
      SELECT time||' $sep$appnam$sepmulti','\n\n'||note||'\n' FROM Tmain WHERE title='$activeT' order by time desc;">"$appsql"
      sqlite3 "$appdb" <"$appsql">>"$apptxt"
  fi
  # Present the notes to the user (get the  "before" md5sum, to compare with user's access/mods)  
  md5bef=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
  leafpad "$apptxt" # The script waits for the user to close "leafpad"
  md5aft=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
  # Check for any modifications to the notes
  if [ "$md5bef" == "$md5aft" ] ; then
      # No changes have been made.
      exit 0
  fi
  # The notes have been modified. Commit the changes!
  # It's time to analyze the changes, and tidy up.
  #   Remove leading and trailing blank lines (per timestamp).
  #   Delete rows for which the timestamp has been removed.
  #   Update the table for all the remaining rows.
  note=""
  lnCt=0
  while read line ; do
      lnCt=$((lnCt+1))
      [ "$lnCt" -eq "1" ] && continue  # The first line is a throw-away copy of the "title"
      # Find timeline. Any leading data is lost. (It shouldn't be there... common-sense!)
      if [[ "$line" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}\ ∘.*∘$ ]] ; then
          # FOUND timeline
          if [ "$note" != "" ] ; then
              FinalizeNote "$activeT" "$note" "$timeline" "$preList"
          fi
          note=""
          timeline=$line
      elif [ "$line" = "" ] ; then
          if [ "$note" != "" ] ; then
              note="$note$line"$'\n' # append this blank line
          fi
      else
          note="$note$line"$'\n' # append this non-blank line
      fi 
  done <"$apptxt"
  #
  if [ "$note" != "" ] ; then
      FinalizeNote "$activeT" "$note" "$timeline" "$preList"
  fi
  # Delete rows for timestamps still in the PRE-LIST
  while read line ; do
      eval $(echo "$line" |sed -n "s/.*|\([0-9]\+\)$/id=\1/p")
      sqlite3 "$appdb" "DELETE FROM Tmain WHERE id='$id';"
  done <"$preList"

exit 

############################################################################
1
ответ дан 13 August 2018 в 16:52
  • 1
    Вы должны принять это как ответ, это фантастика! И спасибо за объяснение, а не только за сообщение кучки непрозрачных команд. – Stefano Palazzo♦ 5 January 2011 в 01:14

Хм, лучшее, что я могу представить, входит в ccsm и играет с выбором окон по имени (я бы начал с плагина «Правила оформления окон»). Есть способ перемещения или липкие окна по имени, поэтому, если вы назвали свои окна уникальными, и вы были умны, возможно, это могло бы работать ...

0
ответ дан 25 May 2018 в 23:45
  • 1
    Syzygy .. спасибо за эту мысль, но то, что я ищу, - это то, что будет автоматически и quot; создайте пустое примечание, основанное на заголовке окна, а затем, после ввода некоторой информации, я могу вспомнить эту заметку с помощью той же клавиши быстрого доступа, либо когда я вхожу в окно, либо самостоятельно просматриваю все собранные заметки. Если ничего уже не существует, я сам буду грубить что-то вместе ... это кажется довольно простой идеей, и небольшой целевой проект - лучший способ узнать, особенно если вы поцарапаете свой собственный зуд ... но предварительно сделанное приложение было бы предпочтительнее. – Peter.O 29 December 2010 в 21:48

Хм, лучшее, что я могу представить, входит в ccsm и играет с выбором окон по имени (я бы начал с плагина «Правила оформления окон»). Есть способ перемещения или липкие окна по имени, поэтому, если вы назвали свои окна уникальными, и вы были умны, возможно, это могло бы работать ...

0
ответ дан 25 July 2018 в 22:41
  • 1
    Syzygy .. спасибо за эту мысль, но то, что я ищу, - это то, что будет автоматически и quot; создайте пустое примечание, основанное на заголовке окна, а затем, после ввода некоторой информации, я могу вспомнить эту заметку с помощью той же клавиши быстрого доступа, либо когда я вхожу в окно, либо самостоятельно просматриваю все собранные заметки. Если ничего уже не существует, я сам буду грубить что-то вместе ... это кажется довольно простой идеей, и небольшой целевой проект - лучший способ узнать, особенно если вы поцарапаете свой собственный зуд ... но предварительно сделанное приложение было бы предпочтительнее. – Peter.O 29 December 2010 в 21:48

Хм, лучшее, что я могу представить, входит в ccsm и играет с выбором окон по имени (я бы начал с плагина «Правила оформления окон»). Есть способ перемещения или липкие окна по имени, поэтому, если вы назвали свои окна уникальными, и вы были умны, возможно, это могло бы работать ...

0
ответ дан 2 August 2018 в 04:07
  • 1
    Syzygy .. спасибо за эту мысль, но то, что я ищу, - это то, что будет автоматически и quot; создайте пустое примечание, основанное на заголовке окна, а затем, после ввода некоторой информации, я могу вспомнить эту заметку с помощью той же клавиши быстрого доступа, либо когда я вхожу в окно, либо самостоятельно просматриваю все собранные заметки. Если ничего уже не существует, я сам буду грубить что-то вместе ... это кажется довольно простой идеей, и небольшой целевой проект - лучший способ узнать, особенно если вы поцарапаете свой собственный зуд ... но предварительно сделанное приложение было бы предпочтительнее. – Peter.O 29 December 2010 в 21:48

Хм, лучшее, что я могу представить, входит в ccsm и играет с выбором окон по имени (я бы начал с плагина «Правила оформления»). Есть способ перемещения или липкие окна по имени, поэтому, если вы назвали свои окна уникальными, и вы были умны, возможно, это могло бы работать ...

0
ответ дан 4 August 2018 в 20:10

Хм, лучшее, что я могу представить, входит в ccsm и играет с выбором окон по имени (я бы начал с плагина «Правила оформления»). Есть способ перемещения или липкие окна по имени, поэтому, если вы назвали свои окна уникальными, и вы были умны, возможно, это могло бы работать ...

0
ответ дан 6 August 2018 в 04:12

Хм, лучшее, что я могу представить, входит в ccsm и играет с выбором окон по имени (я бы начал с плагина «Правила оформления»). Есть способ перемещения или липкие окна по имени, поэтому, если вы назвали свои окна уникальными, и вы были умны, возможно, это могло бы работать ...

0
ответ дан 10 August 2018 в 10:25

Хм, лучшее, что я могу представить, входит в ccsm и играет с выбором окон по имени (я бы начал с плагина «Правила оформления»). Есть способ перемещения или липкие окна по имени, поэтому, если вы назвали свои окна уникальными, и вы были умны, возможно, это могло бы работать ...

0
ответ дан 13 August 2018 в 16:52
  • 1
    Syzygy .. спасибо за эту мысль, но то, что я ищу, - это то, что будет автоматически и quot; создайте пустое примечание, основанное на заголовке окна, а затем после ввода некоторой информации я могу вспомнить эту заметку с помощью той же самой клавиши быстрого доступа, либо когда я вхожу в окно, либо самостоятельно просматриваю все собранные заметки. Если ничего уже не существует, я сам буду грубить что-то вместе ... это кажется довольно простой идеей, и небольшой целевой проект - лучший способ узнать, особенно если вы поцарапаете свой собственный зуд ... но предварительно сделанное приложение было бы предпочтительнее. – Peter.O 29 December 2010 в 21:48

Другие вопросы по тегам:

Похожие вопросы: