All Projects → erichs → Composure

erichs / Composure

Licence: other
Don't fear the Unix chainsaw

Programming Languages

shell
77523 projects
bash
514 projects

Projects that are alternatives of or similar to Composure

Nave
Virtual Environments for Node
Stars: ✭ 1,495 (+449.63%)
Mutual labels:  versioning, zsh
Resh
Rich Enhanced Shell History - Contextual shell history for zsh and bash
Stars: ✭ 310 (+13.97%)
Mutual labels:  zsh, metadata
zsh-poetry
🐚 Simple ZSH plugin for automatically activating and deactivating Poetry-created virtualenvs. 🐍
Stars: ✭ 43 (-84.19%)
Mutual labels:  zsh
.dotfiles
There's no place like ~ !
Stars: ✭ 265 (-2.57%)
Mutual labels:  zsh
Bioformats
Bio-Formats is a Java library for reading and writing data in life sciences image file formats. It is developed by the Open Microscopy Environment. Bio-Formats is released under the GNU General Public License (GPL); commercial licenses are available from Glencoe Software.
Stars: ✭ 256 (-5.88%)
Mutual labels:  metadata
spotify-url-info
Get metadata from Spotify URL.
Stars: ✭ 34 (-87.5%)
Mutual labels:  metadata
Pgmemento
Audit trail with schema versioning for PostgreSQL using transaction-based logging
Stars: ✭ 260 (-4.41%)
Mutual labels:  versioning
cloud-computer
☁️ The Cloud Native Computer
Stars: ✭ 5 (-98.16%)
Mutual labels:  zsh
Irs
🎸 🎶 A music downloader that understands your metadata needs.
Stars: ✭ 268 (-1.47%)
Mutual labels:  metadata
arm-server
📃 A service for mapping Anime ID's between AniList, AniDB, MAL, and Kitsu (using https://github.com/manami-project/anime-offline-database)
Stars: ✭ 46 (-83.09%)
Mutual labels:  metadata
Shrine
File Attachment toolkit for Ruby applications
Stars: ✭ 2,903 (+967.28%)
Mutual labels:  metadata
ranger-autojump
The combined magic of autojump, ranger and zsh
Stars: ✭ 59 (-78.31%)
Mutual labels:  zsh
dotfiles
Configs for apps I care about
Stars: ✭ 19 (-93.01%)
Mutual labels:  zsh
Nord Gnome Terminal
An arctic, north-bluish clean and elegant GNOME Terminal color theme.
Stars: ✭ 258 (-5.15%)
Mutual labels:  zsh
fmf
Flexible Metadata Format
Stars: ✭ 16 (-94.12%)
Mutual labels:  metadata
Python Semver
Python package to work with Semantic Versioning (http://semver.org/)
Stars: ✭ 264 (-2.94%)
Mutual labels:  versioning
tipz
Gives you helpful hints when you execute a command for which you have an alias defined
Stars: ✭ 24 (-91.18%)
Mutual labels:  zsh
dotfiles
My dot files
Stars: ✭ 25 (-90.81%)
Mutual labels:  zsh
Dotfiles
My dotfiles
Stars: ✭ 258 (-5.15%)
Mutual labels:  zsh
Calver
📅 The web's go-to resource for Calendar Versioning info.
Stars: ✭ 271 (-0.37%)
Mutual labels:  versioning
 e88~~\  e88~-_  888-~88e-~88e 888-~88e   e88~-_   d88~\ 888  888 888-~\  e88~~8e
d888    d888   i 888  888  888 888  888b d888   i C888   888  888 888    d888  88b
8888    8888   | 888  888  888 888  8888 8888   |  Y88b  888  888 888    8888__888
Y888    Y888   ' 888  888  888 888  888P Y888   '   888D 888  888 888    Y888    ,
 "88__/  "88_-~  888  888  888 888-_88"   "88_-~  \_88P  "88_-888 888     "88___/
                               888

# Composure: don't fear the Unix chainsaw

These light-hearted functions make programming the shell easier and more intuitive:

  • Transition organically from command, to function, to script
  • Use an unobtrusive help system with arbitrary shell metadata
  • Automatically version and store your shell functions with Git

static analysis and automated tests: Build Status

Demo!

Composing a simple network monitoring script (4 minutes)

Compatibility

Composure is POSIX-compliant, and is known to work on ksh93, zsh, and bash, on osx and linux.

Please feel free to open an issue if you have any difficulties on your system.

Installing

Put composure.sh where you'd like it to live and source it from your shell's profile or rc file.

On Bash:

    cd /your/favorite/directory
    curl -L http://git.io/composure > composure.sh
    chmod +x composure.sh
    echo "source $(pwd)/composure.sh" >> ~/.bashrc   # or, ~/.bash_profile on osx

Users upgrading from a version prior to 1.1.0 need to execute the following commands, as the directory for composure's local repo has changed:

  mkdir ~/.local 2>/dev/null
  mv ~/.composure ~/.local/composure

Craft - Draft - Revise - Write

Crafting the command line

REPL environments are great for trying out programming ideas and crafting snippets of working code, aren't they? Composure helps you make better use of the REPL environment constantly at your fingertips: the shell.

Many Unix users I know like to iteratively build up complex commands by trying something out, hitting the up arrow and perhaps adding a filter with a pipe:

  $ cat servers.txt
  bashful: up
  doc: down

  up-arrow

  $ cat servers.txt | grep down
  doc: down

  up-arrow

  $ cat servers.txt | grep down | mail -s "down server(s)" [email protected]

Composure helps by letting you quickly draft simple shell functions, breaking down your long pipe filters and complex commands into readable and reusable chunks.

Draft first, ask questions later

Once you've crafted your gem of a command, don't throw it away! Use 'draft ()' and give it a good name. This stores your last command as a function you can reuse later. Think of it like a rough draft.

  $ cat servers.txt
  bashful: up
  doc: down

  up-arrow

  $ cat servers.txt | grep down
  doc: down

  $ draft finddown

  $ finddown | mail -s "down server(s)" [email protected]

Revise, revise, revise!

Now that you've got a minimal shell function, you may want to make it better through refactoring and revision. Use the 'revise ()' command to revise your shell function in your favorite editor.

  • generalize functions with input parameters
  • add or remove functionality
  • add supporting metadata for documentation
  $ revise finddown
  finddown ()
  {
      about finds servers marked 'down' in text file
      group admin
      cat $1 | grep down
  }

  $ finddown servers.txt
  doc: down

Get it in Writing

When it is time to put your function or functions to use in a shell script, just call write:

  $ write finddown > finddown.sh

Edit the main() function, chmod +x, and you're ready to go!

Arbitrary shell metadata!

Composure uses a simple system of dynamic keywords that allow you to add metadata to your functions. Just call 'cite ()' to initialize your new keyword(s), and use them freely in your functions:

  foo()
  {
      cite about
      about perform mad script-foo
      echo 'foo'
  }

Retrieve your metadata later by calling 'metafor ()':

  typeset -f foo | metafor about  # displays:
  perform mad script-foo

By default, composure knows the keywords: about, param, group, author, and example.

These default keywords are used by the help system:

Intuitive help system

The 'glossary ()' function will automatically summarize all functions with 'about' metadata. If called with a 'group' name as a parameter, it will summarize functions belonging to that group.

To display apidoc-style help for a function, use 'reference ()'.

  $ glossary   # displays:
  cite                creates a new meta keyword for use in your functions
  draft               wraps last command into a new function
  finddown            finds servers marked 'down' in text file
  foo                 perform mad script-foo
  glossary            displays help summary for all functions, or summary for a group of functions
  metafor             prints function metadata associated with keyword
  reference           displays apidoc help for a specific function
  revise              loads function into editor for revision
  write               writes one or more composed function definitions to stdout

  meanwhile

  $ glossary admin   # displays:
  finddown            finds servers marked 'down' in text file

  and

  $ reference draft  # displays:
  draft               wraps last command into a new function
  parameters:
                      1: name to give function
  examples:
                      $ ls
                      $ draft list
                      $ list

Git integration

If you already use git, installing composure will initialize a ~/.local/composure repository, and store and version your functions there. Just use 'draft ()' and 'revise ()', they automatically version for you.

Composure supports the XDG Base Directory specification, and will respect your local XDG_DATA_HOME environment variable.

Why do this?

  • the latest version of any function you've composed may always be sourced from your composure repo
  • never throw away code--keep your one-off functions in your composure 'junk drawer', and grep through it later for long-forgotten gems
  • every version of every function you write is always available to you via basic git commands

Persistent access

Draft or revise a function, and the latest version is automatically sourced into your current shell environment. By default, composure automatically sources all of your composed functions when you source the composure.sh script. If you are concerned about shell startup time, have many hundreds of versioned shell functions, or otherwise want to control which functions are loaded from your composure repository, you may disable the default behavior by adding the following line to your shell's startup script:

export LOAD_COMPOSED_FUNCTIONS=0

Credits

Composure grew out of ideas taken from from Gary Bernhardt's hilarious talk The Unix Chainsaw (31 minutes), which refers to the Elements of Programming described in MIT's SICP text:

  • primitive expressions
  • means of combination
  • means of abstraction

Known Issues

'glossary ()' and 'reference ()' do not support nested functions with metadata.

revise works well if your editor is terminal-based, like Emacs or Vim. If you use a windowed editor like Atom, VSCode, or Sublime, you will need to check to see if your editor supports a flag argument that allows it to wait for the files to be closed before returning. If this is supported, you can create a small script to launch your editor in this mode, and specify that script path in your EDITOR var. See https://github.com/erichs/composure/issues/10.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].