dotfiles

[!TIP|label:references:]

highlight

highlight output

[!TIP] references:

ack

$ curl -sg https://api.domain.com | ack --passthru 'keyword'

less

$ curl -sg https://api.domain.com | less -i -p 'keyword'

grep

$ command | grep --color=always 'pattern\|$'
$ command | grep --color=always -E 'pattern|$'
$ command | egrep --color=always 'pattern|$'
  • example

    $ curl -sg 'https://api.domain.com | jq -r . | grep --color=always '.*keyword.*\|$'
    
    # or
    $ curl -sg 'https://api.domain.com | jq -r . | grep --color=always -E '| .*keyword.*'
    

highlight

[!TIP] Highlight was designed to offer a flexible but easy to use syntax highlighter for several output formats. Instead of hardcoding syntax or colouring information, all relevant data is stored in configuration scripts. These scripts may be altered or enhanced with plug-in scripts.

$ highlight -i git.groovy -o git.groovy.html --syntax groovy --inline-css --include-style --line-numbers

ccat

[!TIP] ccat is the colorizing cat. It works similar to cat but displays content with syntax highlighting.

$ ccat /path/to/file.groovy

# output html format
$ ccat file.py --bg=dark --html

# get colors
$ ccat --palette

render visualization of hexadecimal colors

[!NOTE|label:references:]

  • #2705 Render visualization of hexadecimal colors (or other common formats) using true color ANSI escape sequences
    # colorcat
    # - cats a file, but if any line contains N hex colors, it appends the colors
    #   (rendered as ansi escape sequences) to the end of the line.
    # - input can be stdin, a file, or a hex color in plain text
    function colorcat() {
    if [[ "$#" -eq 1 && ! -f "$1" ]]; then
      echo "$1"
    else
      cat "$@"
    fi | while read -r line; do
      local colors=""
      for word in $line; do
        if [[ "$word" =~ ^[^A-Fa-f0-9]*#?([A-Fa-f0-9]{6})[^A-Fa-f0-9]*$ ]]; then
          hex=${BASH_REMATCH[1]}
          local r=$((16#${hex:0:2}))
          local g=$((16#${hex:2:2}))
          local b=$((16#${hex:4:2}))
          local truecolor="\033[48;2;${r};${g};${b}m"
          local reset="\033[0m"
          colors="${colors}${truecolor}  ${reset} "
        fi
      done
        echo -e "$line $colors"
    done
    }
    

others

remove highlight

[!TIP] references:

$ <cmd> | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g"

# or
$ alias decolorize='sed -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[mGKHfJ]//g"'
# deprecated
# $ alias decolorize='sed -r "s/\\x1B\\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g"'
$ command | decolorize
  • tips

    $ git br -a | cat -A
    * ^[[1;32mmarslo^[[m$
      ^[[31mremotes/origin/marslo^[[m$
      ^[[31mremotes/origin/gh-pages^[[m$
      ^[[31mremotes/origin/gitbook^[[m$
      ^[[31mremotes/origin/master^[[m$
      ^[[33mgh-pages^[[m$
      ^[[33mmaster^[[m$
      ^[[31mremotes/origin/sample^[[m$
    
    $ git br -a | decolorize | cat -A
    * marslo$
      remotes/origin/marslo$
      remotes/origin/gh-pages$
      remotes/origin/gitbook$
      remotes/origin/master$
      gh-pages$
      master$
      remotes/origin/sample$
    

terminal ui

dialog

[!NOTE|label:references:]

dialog
1.2.5.1 -- dialog
# macos
$ brew install dialog

# ubuntu/debian
$ sudo apt-get install dialog
  • create a yes/no dialog box

    if dialog --title "Confirm" --yesno "Are you sure you want to continue?" 7 50; then
      echo "Confirmed"
    else
      echo "Cancelled"
    fi
    
  • input box

    input=$(dialog --inputbox "Enter your name:" 8 40 "e.g. marslo" 3>&1 1>&2 2>&3)
    echo $input
    
  • multiple choice

    choices=$(dialog --checklist "Select options:" 10 40 3 \
      1 "Option 1" off \
      2 "Option 2" on \
      3 "Option 3" off \
      3>&1 1>&2 2>&3)
    echo $choices
    
  • multiple lines input box

    tempfile=$(mktemp)
    dialog --editbox "$tempfile" 20 60 2> "$tempfile"
    content=$(< "$tempfile")
    rm -f "$tempfile"
    echo "Edited content:"
    echo "$content"
    

gum

[!NOTE|label:references:]

gum choose
1.2.5.2 -- gum choose
  • spinner

    $ gum spin --spinner dot --title "Loading..." -- sleep 3
    
  • filter

    $ find . -type f | gum filter --placeholder "Search file..."
    
  • single select

    $ gum choose "fix" "feat" "docs" "style" "refactor" "test" "chore" "revert"
    
  • multiple select

    $ echo -e "red\ngreen\nblue" | gum choose --no-limit
    
  • input box

    $ gum input --placeholder "Enter your commit message"
    
  • multiple line input box

    $ gum write --placeholder "Enter your commit message"
    
  • yes or no

    $ gum confirm "Commit changes?" && git commit -m "$SUMMARY" -m "$DESCRIPTION"
    
    # or
    $ if gum confirm "Are you sure you want to continue?"; then
        echo "Confirmed"
      else
        echo "Cancelled"
      fi
    

zenity

[!NOTE|label:references:]

  • calendar

    $ zenity --calendar --title="Select a Date" --text="Click on a date to select that date." --day=$(date +%d) --month=$(date +%-m) --year=$(date +%Y) 2>/dev/null
    
    zenity calendar
    1.2.5.3 -- zenity calendar
  • color picker

    $ zenity --color-selection --show-palette 2>/dev/null
    
    zenity color picker
    1.2.5.4 -- zenity color picker
  • password

    $ zenity --password --username 2>/dev/null
    
    # or
    $ zenity --password --title="Authentication Required" 2>/dev/null
    
    zenity password
    1.2.5.5 -- zenity password
  • progress bar

    (
    echo "10" ; sleep 1
    echo "# Updating mail logs" ; sleep 1
    echo "20" ; sleep 1
    echo "# Resetting cron jobs" ; sleep 1
    echo "50" ; sleep 1
    echo "This line will just be ignored" ; sleep 1
    echo "75" ; sleep 1
    echo "# Rebooting system" ; sleep 1
    echo "100" ; sleep 1
    ) |
    zenity --progress \
      --title="Update System Logs" \
      --text="Scanning mail logs..." \
      --percentage=0 2>/dev/null
    
    if [ "$?" = -1 ] ; then
      zenity --error --text="Update canceled."
    fi
    
    zenity progress bar
    1.2.5.6 -- zenity progress bar
  • list

    $ zenity --list \
             --title="Choose the Bugs You Wish to View" \
             --column="Bug Number" --column="Severity" --column="Description" \
               992383 Normal "GtkTreeView crashes on multiple selections" \
               293823 High "GNOME Dictionary does not handle proxy" \
               393823 Critical "Menu editing does not work in GNOME 2.0" \
             2>/dev/null
    
    # or
    $ zenity --list --title="Select an option" --column="Options" "Option 1" "Option 2" "Option 3" 2>/dev/null
    
    zenity list
    1.2.5.7 -- zenity list
  • entry

    $ zenity --entry --title="User Input" --text="Enter your name:" --entry-text="e.g. marslo" 2>/dev/null
    

    ![zenity entry](../screenshot/linux/tui/zenity--entry.png

  • text info

    $ zenity --text-info --title="File Content" --filename="/path/to/file.txt" --width=600 --height=400 2>/dev/null
    
  • info/warning/error

    $ zenity --info --title="Information" --text="Operation completed successfully." 2>/dev/null
    

bubbles

[!NOTE|label:references:]

alias

[!NOTE|label:references:]

$ echo ${BASH_ALIASES[ls]}
ls --color=always

bash -<parameter>

  • get bash login log ( for rc script debug )

    $ bash -l -v
    
  • run with only one startup file ( for sharing accounts )

    $ bash -i --rcfile="$HOME/.marslo/.imarslo"
    

authentication

special characters in usernames and passwords

references:

CHARACTERS PERCENT-ENCODED
] %5D
[ %5B
? %3F
/ %2F
< %3C
~ %7E
# %23
``` %6D
! %21
@ %40
$ %24
% %25
^ %5E
& %26
* %2A
( %28
) %29
+ %2B
= %3D
} %7D
` %7C
: %3A
" %22
; %3B
' %27
, %2C
> %3E
{ %7B
space %20

others

$ grep -oP '"url":"\K[^"]+' $(ls -t ~/.mozilla/firefox/*/sessionstore.js | sed q)

downlaods bookmark

[!TIP|label:references:]

extract fonts from pdf

$ python3 -m pip install pdfminer
$ python3 -m pip install pdfminer.six
$ python3 pdf_font_report.py input.pdf --format csv --output result.csv
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import csv
from pdfminer.high_level import extract_pages
from pdfminer.layout import LTTextContainer, LTChar, LTTextLine, LTTextBox

def analyze_pdf_fonts(pdf_path, output_format=None, output_file=None):
    rows = []

    for page_number, page_layout in enumerate(extract_pages(pdf_path), start=1):
        for element in page_layout:
            if isinstance(element, LTTextContainer):
                for text_line in element:
                    if hasattr(text_line, "__iter__"):
                        for character in text_line:
                            if isinstance(character, LTChar):
                                char = character.get_text()
                                font = character.fontname
                                size = round(character.size, 2)
                                rows.append((page_number, char, font, size))
                    elif isinstance(text_line, LTChar):
                        # handle case where element is directly a character
                        char = text_line.get_text()
                        font = text_line.fontname
                        size = round(text_line.size, 2)
                        rows.append((page_number, char, font, size))

    if output_format == "markdown":
        print("| Page | Char | Font | Size |")
        print("|------|------|------|------|")
        for row in rows:
            print(f"| {row[0]} | `{row[1]}` | `{row[2]}` | {row[3]} |")

    elif output_format == "csv":
        if not output_file:
            output_file = "font_report.csv"
        with open(output_file, "w", newline="", encoding="utf-8") as csvfile:
            writer = csv.writer(csvfile)
            writer.writerow(["Page", "Char", "Font", "Size"])
            writer.writerows(rows)
        print(f"[✓] CSV report saved to: {output_file}")

    else:
        # Default: plain text output
        for row in rows:
            print(f"Page {row[0]}: '{row[1]}' → {row[2]} ({row[3]}pt)")

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Extract character-font-size info from PDF")
    parser.add_argument("pdf", help="Path to input PDF file")
    parser.add_argument("-f", "--format", choices=["markdown", "csv"], help="Output format")
    parser.add_argument("-o", "--output", help="Output file (for CSV)")
    args = parser.parse_args()

    analyze_pdf_fonts(args.pdf, args.format, args.output)
Copyright © marslo 2020-2025 all right reserved,powered by GitbookLast Modified: 2025-08-25 20:17:04

results matching ""

    No results matching ""