Skip to content

Instantly share code, notes, and snippets.

@igorlg
Created September 9, 2019 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorlg/5734adca9f78ec3b699ec64e94d3540f to your computer and use it in GitHub Desktop.
Save igorlg/5734adca9f78ec3b699ec64e94d3540f to your computer and use it in GitHub Desktop.
Generate Install script for your Atom Plugins
apm list -e --no-dev -i -p -j \
| jq -cM '.user[] | { name: .name, url: .homepage, desc: .description}' \
| while read line; do
name="$(echo $line | jq -cr '.name')"
desc="$(echo $line | jq -cr '.desc')"
url="$(echo $line | jq -cr '.url' | sed 's/^\(.*\)#.*$/\1/')"
if [ "${#desc}" -gt "95" ]; then desc="$(echo $desc | cut -c 1-100) [...]"; fi
printf 'apm install %s***# %s (%s)\n' "$name" "$desc" "$url"
done \
| column -t -s "***"

Breaking down the script

apm list -p -e --no-dev -i -j \

List (apm list) packages (-p) that are enabled (-e), excluding dev packages (--no-dev), that are installed (-i) in JSON format (-j)

  | jq -cM '.user[] | { name: .name, url: .homepage, desc: .description}' \

Grab from output with JQ only the package name, homepage and description

  | while read line; do

Loop through returned lines and

      name="$(echo $line | jq -cr '.name')"
      desc="$(echo $line | jq -cr '.desc')"
      url="$(echo $line  | jq -cr '.url' | sed 's/^\(.*\)#.*$/\1/')"

Extract name, description and url into shell variables

      if [ "${#desc}" -gt "95" ]; then desc="$(echo $desc | cut -c 1-100) [...]"; fi

Truncates the description (desc variable) if its longer than 95 characters

      printf 'apm install %s***# %s (%s)\n' "$name" "$desc" "$url"

Prints the install command, plus a comment with the description and URL, e.g.:

apm install advanced-open-file              # Open and create files and directories easily. Type in a path (with autocomplete) and view directory  [...] (https://github.com/Osmose/advanced-open-file)
  | column -t -s "***"

Parses the printed output from the while loop and indents the commands and comments in columns, like so:

$ ./atom_plugin_install.sh
apm install Sublime-Style-Column-Selection  # Enable Sublime style 'Column Selection'. Just hold 'alt' while you select, or select using your midd [...] (https://github.com/bigfive/atom-sublime-select)
apm install advanced-open-file              # Open and create files and directories easily. Type in a path (with autocomplete) and view directory  [...] (https://github.com/Osmose/advanced-open-file)
apm install atom-alignment                  # A simple key-binding for aligning multi-line and multiple selections in Atom (Based on the sublime t [...] (https://github.com/Freyskeyd/atom-alignment)
apm install compare-files                   # Compares two files and show the diff (https://github.com/atom-compare-files/atom-compare-files)
apm install file-icons                      # Assign file extension icons and colours for improved visual grepping (https://github.com/file-icons/atom)
apm install git-blame                       # Toggle git-blame annotations in the gutter of atom editor. (https://github.com/alexcorre/git-blame)
apm install git-diff-details                # View git diffs directly in atom. (https://github.com/samu/git-diff-details)
apm install git-line                        # Displays a tooltip with git-blame information about the currently selected line. (https://github.com/joelgardner/git-line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment