Linux stuff

Jump to: navigation, search

What it is

A page of trivial Linux stuff.

Why was it created

I got into Linux.

Tmuxinator - first steps

If you're familiar with creating multiple Linux (etc.) Terminal windows then you may have heard of 'Tmux' and/or 'Tmuxinator'. I'll be honest, I'm totally new to Ubuntu Linux so most of this is probably obvious to you.

Multiple Terminal windows could be opened and resized to achieve a useful working environment but as soon as you want to open another application your carefully-crafted layout's usability begins to fall apart. Tmux - a text-based (non-GUI) windowing system to the rescue!

(What follows is not intended to be a primer.)

After installing Tmux and the things it's dependent on, launching the program subtly changes the Terminal window - adding a green status bar at its base. It turns out that the commands to create new windows and panes within them are relatively straightforward, e.g.:

ctrl-B % - splits a window or pane into 2 vertical panes,
ctrl-B " - splits a window or pane into 2 horizontal panes
ctrl-B N - places focus in the next window
ctrl-B [cursor left or right] - places focus in the next pane along
ctrl-B [ - allows unlimited scroll within the current pane
typing 'exit' closes the currently-active pane or window

...and this is just scratching the surface!

Tmuxinator makes it relatively easy to create windows and panes and add content to them automatically. Here's a simple layout file:

# ~/.tmuxinator/ayadn.yml

name: ayadn

root: ~/

  - Timeline:
      layout: main-vertical
        - ayadn timeline -s
        - ayadn write
        - ayadn mentions bazbt3
  - Timeline200:
      layout: main-vertical
        - ayadn write
        - ayadn timeline -c200
  - ayadn3:
      layout: main-vertical
        - ayadn help send
        - ayadn channels

The interesting bit starts at 'windows'.

Nested within the first window it creates, called 'Timeline', is a 2-column preset layout called main-vertical - addin 3 panes. One calls up a scrolling Ayadn timeline, the next an Ayadn post window and the third, my most recent mentions. The interesting thing about this one, the third command automatically splits the second pane.

The second, 'Timeline200', creates a 2-pane window, the left-most a post pane and the right-most displaying the last 200 posts.

The last window, 'ayadn3', displays Ayadn help for its 'send' command in the left pane, and lists all PM and Patter channels I've posted to in the right pane.

It saves a minute-or-two of setup time for - in this instance - each Ayadn session.

Tmuxinator - evolution

For something much better-developed, please take a look at my ayadn_shell page - a rudimentary menu system for Ayadn, the command line client by @ericd. My stuff is mainly intended to showcase Ayadn and provide a gentle introduction to Tmux and Tmuxinator.

My first shell script

An example shell script - very loosely-related to the subject matter above.

# ~/Documents/

# My first-ever Linux shell script - borrows from a disparate set of
# likely-unsuitable-for-this-purpose commands dragged from all
# over a small selection of sites.
# Sorry but I forgot to bookmark stuff.

# Change to the User's Documents folder
cd ~/Documents

# Clear the contents of ayadnmsgs.txt (no-op overwrites the file)
: > ayadnmsgs.txt

# Setup an array called adnnames - using aliases I've preciously setup in Ayadn
adnnames=( wiki-workers cookieclub wedc 10cblog ericd )

# Start a loop using variable i and do something with the contents of the array until the last element is exhausted
for i in "${adnnames[@]}"
# Execute ayadn to append the last 2 messages from each channel to text file ayadnmsgs.txt
    ayadn messages -c2 $i >> ayadnmsgs.txt

# Replace some of the text with dashes to tidy a bit
sed -i 's/Downloading from ADN.../-----/g' ayadnmsgs.txt

# Display the contents of the file created above, display some non-printing characters
cat -v ayadnmsgs.txt

# Indicate that the script has run:
echo Success!

External links