irthomasthomas / undecidability

2 stars 1 forks source link

Script to Github Issues #5

Open irthomasthomas opened 9 months ago

irthomasthomas commented 9 months ago

I wrote a script to add markdown code comments to github issues, but I couldn't figure out the formatting while nesting scripts in scripts in markdown.


    cmd="$1" 
    title=$(echo $cmd | cut -d' ' -f2) 
    output=$(eval "$cmd") 
    token_count=$(ttok "$output") 
    formatted_output="## Command <a id='command'></a>
    \`\`\`
    ${cmd}
    \`\`\`
    [Link to Command](#command)

    ## Token Count <a id='token_count'></a>
    \`\`\`
    ${token_count}
    \`\`\`
    [Link to Token Count](#token_count)

    ## Output <a id='output'></a>
    \`\`\`
    ${output}
    \`\`\`
    [Link to Output](#output)
    " 
    echo -e "$formatted_output"
} ```
irthomasthomas commented 9 months ago
  cmd="$1" 
  title=$(echo $cmd | cut -d' ' -f2) 
  output=$(eval "$cmd") 
  token_count=$(ttok "$output") 
  formatted_output="## Command <a id='command'></a>
    \`\`\`
    ${cmd}
    \`\`\`
    [Link to Command](#command)

    ## Token Count <a id='token_count'></a>
    \`\`\`
    ${token_count}
    \`\`\`
    [Link to Token Count](#token_count)

    ## Output <a id='output'></a>
    \`\`\`
    ${output}
    \`\`\`
    [Link to Output](#output)
    " 
  echo -e "$formatted_output"
} ```

--body 'bash '"$(which cmd_and_output_to_markdown)"''

That didn't work.

irthomasthomas commented 9 months ago

    cmd="$1" 
    title=$(echo $cmd | cut -d' ' -f2) 
    output=$(eval "$cmd") 
    token_count=$(ttok "$output") 
    formatted_output="## Command <a id='command'></a>
    \`\`\`
    ${cmd}
    \`\`\`
    [Link to Command](#command)

    ## Token Count <a id='token_count'></a>
    \`\`\`
    ${token_count}
    \`\`\`
    [Link to Token Count](#token_count)

    ## Output <a id='output'></a>
    \`\`\`
    ${output}
    \`\`\`
    [Link to Output](#output)
    " 
    echo -e "$formatted_output"
}\n```
irthomasthomas commented 9 months ago

Embedding a script in a script apparently needs a heredoc:

cat << MYTEXT
Hello, 
This is a multi-line text
MYTEXT
irthomasthomas commented 9 months ago
 cmd_and_output_to_markdown () {
    cmd="$1" 
    title=$(echo $cmd | cut -d' ' -f2) 
    output=$(eval "$cmd") 
    token_count=$(ttok "$output") 
    formatted_output="## Command <a id='command'></a>
    \`\`\`
    ${cmd}
    \`\`\`
    [Link to Command](#command)

    ## Token Count <a id='token_count'></a>
    \`\`\`
    ${token_count}
    \`\`\`
    [Link to Token Count](#token_count)

    ## Output <a id='output'></a>
    \`\`\`
    ${output}
    \`\`\`
    [Link to Output](#output)
    " 
    echo -e "$formatted_output"
} 
irthomasthomas commented 9 months ago

Got it. No heredoc needed here.

gh issue comment 5 --body "$(echo -e '```bash \n '''"$(which cmd_and_output_to_markdown)"' \n ```')"
irthomasthomas commented 9 months ago
gh issue create --title "Man Page to Text to Embeddings Pipeline"  \ 
--body "$(echo -e '```bash \n '''"$(which cmd_and_output_to_markdown)"' \n ```')" \
--label "inbox-script" --label "embeddings" --label "man-pages"
irthomasthomas commented 9 months ago
bashmark () {
    [[ -n "$1" ]] && bash_string="$1"  || bash_string="'$(paste)'" 
    echo -e '```bash  
'''"${bash_string}"'
```'
}
irthomasthomas commented 9 months ago
md() {

  if [ -z "$1" ] # checks if $1 is empty
  then
    echo "Code body is missing."
    return
  fi
  body="$1"
  info_string_language="${2:-plain}  "

  # Treat remainder of inputs if provided
  if [ -n "$2" ] 
  then
    shift 2
    remainder="${*}"
  fi

  echo -e '```'"${info_string_language}"''"${remainder}"'
'"${body}"'
```'

}
gh issue edit 22 --body "$(echo -e "$(md 'ls -d */*/' 'bash')\n\n$(md "$(paste)" "bash")")"

22

Details

This is some test details.

irthomasthomas commented 9 months ago

Experiment with documenting bash commands and their output.

Command

zcat /usr/share/man/man7/xautomation.7.gz | pandoc -f man -t 

Token Count

330

Link to Token Count

Output

xautomation - control X from the command line, and find things on the
screen

DESCRIPTION

xautomation is a set of command lines programs to control X and do
"visual scraping" to find things on the screen. The control interface
allows mouse movement, clicking, button up/down, key up/down, etc, and
uses the XTest extension so you don't have the annoying problems that
xse has when apps ignore sent events. The visgrep program find images
inside of images and reports the coordinates, allowing programs to find
buttons, etc, on the screen to click on.

xautomation consists in the following programs:

pat2ppm

    Converts an image file from PAT to PPM format.

patextract

    Extract a part of a PNG image file.

png2pat

    Converts an image file from PNG to PAT format.

rgb2pat

    Converts an image file from 24-bit RGB to PAT format

visgrep

    Visual grep, greps for images in another image.

xte

    Generates fake input using the XTest extension.

For more information, please see the individual manpages of these
programs.

SEE ALSO

pat2ppm(1), patextract(1), png2pat(1), rgb2pat(1), visgrep(1), xte(1).

AUTHOR

xautomation was written by Steve Slaven <bpk@hoopajoo.net>.

This manual page was written by Aurelien Jarno <aurel32@debian.org>, for
the Debian project (but may be used by others).

Link to Output

Link to Command

irthomasthomas commented 9 months ago

The raw output of GPT-4 (maybe 3.5) is already formatted for markdown. It can be inserted directly into a new issue/comment/readme

Example: