Changeset - 626f4a46ba00
[Not reviewed]
master
0 1 0
Branko Majic (branko) - 1 month ago 2025-03-07 19:35:30
branko@majic.rs
[cheatsheet_viewer.sh] Keep track of (and display) last opened cheatsheet when using the toggle command.
1 file changed with 23 insertions and 3 deletions:
0 comments (0 inline, 0 general) First comment
utils/cheatsheet_viewer.sh
Show inline comments
 
@@ -104,7 +104,9 @@ toggle [PROFILE]
 
  Toggles display of cheatsheets from the specified profile (default
 
  profile name is 'default'). Unlike the display command, the toggle
 
  command is more intelligent and ensures that only one instance of
 
  cheatsheet-specific pqiv is present.
 
  cheatsheet-specific pqiv is present. Thex toggle command also keeps
 
  track of which cheatsheet was last selected, and will update the
 
  image viewer to point to it when opened.
 

	
 
$PROGRAM accepts the following options:
 

	
 
@@ -300,8 +302,9 @@ function command_toggle() {
 
    local profile="$2"
 
    local profile_dir="$config_dir/profiles/$profile"
 
    local cheatsheets_file="$profile_dir/cheatsheets"
 
    local last_cheatsheet_file="$profile_dir/last"
 

	
 
    local current_process_id current_profile
 
    local current_process_id current_profile last_cheatsheet
 

	
 
    local cheatsheets=()
 

	
 
@@ -319,6 +322,12 @@ function command_toggle() {
 
        return 0
 
    fi
 

	
 
    if [[ -e $last_cheatsheet_file ]]; then
 
        last_cheatsheet=$(< "$last_cheatsheet_file")
 
    else
 
        last_cheatsheet=""
 
    fi
 

	
 
    # Get information about existing running cheatsheet viewer pqiv instance (if any).
 
    current_process_id=$(wmctrl -lp | grep 'cheatsheet-viewer-' | awk '{print $3}')
 
    current_profile=$(wmctrl -lp | grep 'cheatsheet-viewer-' | awk '{print $5}' | sed -e 's/cheatsheet-viewer-//')
 
@@ -339,7 +348,18 @@ function command_toggle() {
 
            "--window-title=cheatsheet-viewer-$profile"
 
        )
 

	
 
        pqiv "${pqiv_options[@]}" "${cheatsheets[@]}" &
 
        if [[ -n $last_cheatsheet && -f $last_cheatsheet ]]; then
 
            pqiv_options+=("--action=goto_file_byname($last_cheatsheet); set_status_output(1)")
 
        else
 
            pqiv_options+=("--action=set_status_output(1)")
 
        fi
 

	
 
        (
 
            while read -r line; do
 
                eval "$line"
 
                echo "$CURRENT_FILE_NAME" > "$profile_dir/last"
 
            done < <(pqiv "${pqiv_options[@]}" "${cheatsheets[@]}" | grep --line-buffered '^CURRENT_FILE_NAME=')
 
        ) &
 
    fi
 
}
 

	
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now