Changeset - 88ff60100e1b
[Not reviewed]
0 1 0
Branko Majic (branko) - 1 month ago 2025-03-06 23:04:58
branko@majic.rs
[cheatsheet_viewer.sh] Added command for displaying cheatsheets:

- Simplistic implementation that probably will not be as useful except
for testing things out.
1 file changed with 68 insertions and 0 deletions:
0 comments (0 inline, 0 general) First comment
utils/cheatsheet_viewer.sh
Show inline comments
 
@@ -31,6 +31,7 @@ $PROGRAM $VERSION, simple utility for viewing image cheatsheets
 
Usage:
 
  $PROGRAM [OPTIONS] list
 
  $PROGRAM [OPTIONS] info PROFILE
 
  $PROGRAM [OPTIONS] display [PROFILE]
 
EOF
 
}
 

	
 
@@ -49,6 +50,8 @@ $(usage)
 
$PROGRAM is a simple utility for viewing image cheatsheets with
 
support for multiple profiles.
 

	
 
Cheatsheets are shown using the pqiv image viewer.
 

	
 
All configuration is stored under user's own home directory at:
 

	
 
  - ~/.config/cheatsheet_viewer/
 
@@ -82,6 +85,15 @@ info PROFILE
 
  Shows detailed information about user-specified profile, such as
 
  list of defined cheatsheets etc.
 

	
 
display [PROFILE]
 

	
 
  Arguments:
 

	
 
    PROFILE (profile name)
 

	
 
  Displays cheatsheets from the specified profile (default profile
 
  name is 'default').
 

	
 
$PROGRAM accepts the following options:
 

	
 
    -q
 
@@ -208,6 +220,55 @@ function command_info() {
 
}
 

	
 

	
 
#
 
# Displays configured cheatsheets from a profile.
 
#
 
# Arguments:
 
#
 
#   $1 (config_dir)
 
#     Base directory under which all configuration files are stored.
 
#
 
#   $2 (profile)
 
#     Profile name.
 
#
 
# Returns:
 
#   0 on success, 1 otherwise.
 
#
 
function command_display() {
 
    local config_dir="$1"
 
    local profile="$2"
 

	
 
    local profile_dir="$config_dir/profiles/$profile"
 
    local cheatsheets_file="$profile_dir/cheatsheets"
 

	
 
    local cheatsheets=()
 

	
 
    if [[ ! -d $profile_dir ]]; then
 
        error "No such profile found under $profile_dir"
 
        return 1
 
    fi
 

	
 
    if [[ -e $cheatsheets_file ]]; then
 
        readarray -t cheatsheets < <(grep --invert-match --extended-regexp "(^[[:blank:]]*#|^[[:blank:]]*$)" "$cheatsheets_file")
 
    fi
 

	
 
    if (( ${#cheatsheets[@]} == 0 )); then
 
        warning "No cheatsheets are defined under $cheatsheets_file"
 
        return 0
 
    fi
 

	
 
    local pqiv_options=(
 
        "--scale-mode-screen-fraction=1.0"
 
        "--zoom-level=1.0"
 
        "--transparent-background"
 
        "--hide-info-box"
 
        "--window-title=cheatsheet-viewer"
 
    )
 

	
 
    pqiv "${pqiv_options[@]}" "${cheatsheets[@]}" &
 
}
 

	
 

	
 
# Set-up colours for message printing if we're not piping and terminal is
 
# capable of outputting the colors.
 
_COLOR_TERMINAL=$(tput colors 2>&1)
 
@@ -314,6 +375,13 @@ elif [[ $COMMAND == info ]]; then
 

	
 
    command_info "$CONFIG_DIR" "$PROFILE"
 

	
 
elif [[ $COMMAND == display ]]; then
 

	
 
    PROFILE="${1-default}"
 
    shift
 

	
 
    command_display "$CONFIG_DIR" "$PROFILE"
 

	
 
else
 

	
 
    error "Unsupported command: $COMMAND"
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now