<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Michael Welford</title>
    <description>The latest articles on Forem by Michael Welford (@fenetikm).</description>
    <link>https://forem.com/fenetikm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F66940%2F80870611-ade3-4f50-9ce7-065b49022d1f.png</url>
      <title>Forem: Michael Welford</title>
      <link>https://forem.com/fenetikm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/fenetikm"/>
    <language>en</language>
    <item>
      <title>Saving time with a preset Tmux setup</title>
      <dc:creator>Michael Welford</dc:creator>
      <pubDate>Sun, 16 Sep 2018 06:51:16 +0000</pubDate>
      <link>https://forem.com/fenetikm/saving-time-with-a-preset-tmux-setup-3j04</link>
      <guid>https://forem.com/fenetikm/saving-time-with-a-preset-tmux-setup-3j04</guid>
      <description>&lt;p&gt;Programming is all about doing the same thing... &lt;em&gt;over and over again, ad nauseam&lt;/em&gt;. No, not the computer, the poor programmer as they work on similar projects bouncing around all the different tools.&lt;/p&gt;

&lt;p&gt;For example, let's take Drupal development - usually once you are in the midst of it, you may be accessing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An editor (Vim, &lt;em&gt;naturally&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;A terminal for running system commands e.g. &lt;code&gt;drush cr&lt;/code&gt;, &lt;code&gt;drush cedit&lt;/code&gt;, &lt;code&gt;drupal generate:module&lt;/code&gt; etc.&lt;/li&gt;
&lt;li&gt;Maybe a todo list / notes&lt;/li&gt;
&lt;li&gt;Log output&lt;/li&gt;
&lt;li&gt;Watch output e.g. &lt;code&gt;npm run watch&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Test output e.g. &lt;code&gt;phpunit&lt;/code&gt;, &lt;code&gt;codeception&lt;/code&gt; etc.&lt;/li&gt;
&lt;li&gt;File ops e.g. &lt;code&gt;ranger&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Reference material&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That may end up looking a bit like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iwcYs_rV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/rz9x4gcowdk3vj1nlc3i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iwcYs_rV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/rz9x4gcowdk3vj1nlc3i.png" alt="drupal development screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; the Tmux status, bottom left, where it shows that I am in the first window of three.&lt;/p&gt;

&lt;p&gt;As this is typical, wouldn't it be nice if, I don't know, you could run a command such as &lt;code&gt;tmd &amp;lt;name of session&amp;gt;&lt;/code&gt; and it would set everything up &lt;em&gt;just so&lt;/em&gt;. Also, over time, we could then refine this setup and get all the benefits of finessing  it - or have multiple scripts depending on the type of project.&lt;/p&gt;

&lt;h2&gt;
  
  
  The script
&lt;/h2&gt;

&lt;p&gt;No problem, take a look at this script &lt;code&gt;drupal.sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/zsh&lt;/span&gt;

&lt;span class="c"&gt;# Note that this assumes base index of 1&lt;/span&gt;

&lt;span class="c"&gt;# check for existence of required things&lt;/span&gt;
&lt;span class="c"&gt;# $1 is the name of the window&lt;/span&gt;
&lt;span class="c"&gt;# we are in the directory of the drupal project&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$# &lt;/span&gt;&lt;span class="nt"&gt;-eq&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"No arguments supplied, requires name of window."&lt;/span&gt;
    &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;fi

&lt;/span&gt;&lt;span class="nv"&gt;CWD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;SESSION_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# detach from a tmux session if in one&lt;/span&gt;
tmux detach &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null

&lt;span class="c"&gt;# Create a new session, -d means detached itself&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;stty &lt;/span&gt;size&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="c"&gt;# $1 = rows $2 = columns&lt;/span&gt;
tmux new-session &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

tmux new-window &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt;:1 &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s1"&gt;'code'&lt;/span&gt;
tmux new-window &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt;:2 &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s1"&gt;'logs'&lt;/span&gt;
tmux new-window &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt;:3 &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s1"&gt;'zsh'&lt;/span&gt;

&lt;span class="c"&gt;## Logs window&lt;/span&gt;
tmux &lt;span class="k"&gt;select&lt;/span&gt;&lt;span class="nt"&gt;-window&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt;:2

&lt;span class="c"&gt;# Start up the logs listener&lt;/span&gt;
tmux send-keys &lt;span class="s2"&gt;"vbin/tail -f /var/log/apache2/error.log | clog drupal"&lt;/span&gt; C-m

&lt;span class="c"&gt;## Zsh window&lt;/span&gt;
tmux &lt;span class="k"&gt;select&lt;/span&gt;&lt;span class="nt"&gt;-window&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt;:3
tmux rename-window &lt;span class="s1"&gt;'Zsh'&lt;/span&gt;

&lt;span class="c"&gt;## Main Window&lt;/span&gt;
tmux &lt;span class="k"&gt;select&lt;/span&gt;&lt;span class="nt"&gt;-window&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt;:1
tmux rename-window &lt;span class="s1"&gt;'code'&lt;/span&gt;

&lt;span class="c"&gt;# Split into left and right&lt;/span&gt;
tmux split-window &lt;span class="nt"&gt;-h&lt;/span&gt; &lt;span class="nt"&gt;-p30&lt;/span&gt;

&lt;span class="c"&gt;# Right ready for taking commands / tests.&lt;/span&gt;
tmux &lt;span class="k"&gt;select&lt;/span&gt;&lt;span class="nt"&gt;-pane&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; 2
tmux send-keys &lt;span class="s2"&gt;"figlet -f roman Ready! | lolcat -t"&lt;/span&gt; C-m

&lt;span class="c"&gt;# Left for neovim.&lt;/span&gt;
tmux &lt;span class="k"&gt;select&lt;/span&gt;&lt;span class="nt"&gt;-pane&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; 1
tmux send-keys &lt;span class="s2"&gt;"v"&lt;/span&gt; C-m

&lt;span class="c"&gt;# Finally attach to it&lt;/span&gt;
tmux attach &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The process can be broken down as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating a new session&lt;/li&gt;
&lt;li&gt;Creating windows&lt;/li&gt;
&lt;li&gt;Creating panes&lt;/li&gt;
&lt;li&gt;Sending commands to the panes / windows&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Creating a new session
&lt;/h3&gt;

&lt;p&gt;Creating a new session is as simple as &lt;code&gt;tmux new-session -s &amp;lt;name-of-session&amp;gt;&lt;/code&gt;. In the example script I have a bit more going on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a new session, -d means detached itself&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;stty &lt;/span&gt;size&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="c"&gt;# $1 = rows $2 = columns&lt;/span&gt;
tmux new-session &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What I am doing here is getting the current screen resolution and then creating a detached session of that size - the reason being that if you don't specify a size using the &lt;code&gt;-x&lt;/code&gt; parameter then if you try to specify window split sizes it will &lt;em&gt;wig out&lt;/em&gt; since it has no point of reference for "size".&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating windows
&lt;/h3&gt;

&lt;p&gt;Creating a window can be accomplished via &lt;code&gt;tmux new-window -n &amp;lt;name-of-window&amp;gt;&lt;/code&gt;. In the example  we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tmux new-window &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt;:1 &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s1"&gt;'code'&lt;/span&gt;
tmux new-window &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt;:2 &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s1"&gt;'logs'&lt;/span&gt;
tmux new-window &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nv"&gt;$SESSION_NAME&lt;/span&gt;:3 &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s1"&gt;'zsh'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we create three windows - the &lt;code&gt;-t&lt;/code&gt; flag is so that we can specify the target of the windows, which in this case is the session that we just created and the index of where they should appear.&lt;/p&gt;

&lt;p&gt;We can then target windows with &lt;code&gt;tmux select-window -t &amp;lt;name-of-session&amp;gt;:&amp;lt;index&amp;gt;&lt;/code&gt; for further commands.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating panes
&lt;/h3&gt;

&lt;p&gt;Often you will want to split up a window into multiple panes. This can be done with something like &lt;code&gt;tmux split-window -h -p&amp;lt;percentage&amp;gt;&lt;/code&gt; where &lt;code&gt;-h&lt;/code&gt; signifies a horizontal split (guess how a vertical split is specified?) and &lt;code&gt;-p&lt;/code&gt; signifies a percentage split. In the example I create a 30 percent split but you can of course specify by pixel if that is your jam.&lt;/p&gt;

&lt;p&gt;Once you have created one or more splits, you can target panes with &lt;code&gt;tmux select-pane -t &amp;lt;index-of-pane&amp;gt;&lt;/code&gt; for more commands.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sending commands to the panes / windows
&lt;/h3&gt;

&lt;p&gt;Lastly, once we have our windows and panes ready, we can send them further commands to start things up. Some examples from the above:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;tmux send-keys "vbin/tail -f /var/log/apache2/error.log | clog drupal" C-m&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(run the &lt;code&gt;tail&lt;/code&gt; command in watch mode against the apache error log, piped into &lt;a href="https://taskwarrior.org/docs/clog/what.html"&gt;clog&lt;/a&gt; - the &lt;code&gt;C-m&lt;/code&gt; is used to send an &lt;code&gt;&amp;lt;Enter&amp;gt;&lt;/code&gt; to a pane or window)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;tmux send-keys "figlet -f roman Ready! | lolcat -t" C-m&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(run &lt;code&gt;figlet&lt;/code&gt; with the string "Ready!", piped into lolcat in true colour mode )&lt;/p&gt;

&lt;h2&gt;
  
  
  Finishing up
&lt;/h2&gt;

&lt;p&gt;Rounding out the script we have a call to &lt;code&gt;tmux attach -t &amp;lt;name-of-session&amp;gt;&lt;/code&gt; which makes it visible. In the script, the name of the session is passed in as a parameter. For extra convenience I have the following alias in my &lt;code&gt;.zshrc&lt;/code&gt; to run this script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;tmd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'~/.config/tmux/drupal.sh'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Obviously you &lt;em&gt;don't&lt;/em&gt; have to attach to a Tmux session - if you had the need, your script could start up all kinds of processes and then you could attach only to check it whilst doing other things (or not!). Tmux also supports multiple people attaching to a session, sending commands to specific sessions, saving sessions (via plugins) etc. The possibilities &lt;em&gt;runneth over&lt;/em&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article originally appeared on &lt;a href="https://michaelwelford.blog/post/creating-preset-tmux-setup"&gt;michaelwelford.blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>tmux</category>
      <category>productivity</category>
      <category>commandline</category>
      <category>linux</category>
    </item>
    <item>
      <title>Let's put the current iTunes track into the Tmux status line</title>
      <dc:creator>Michael Welford</dc:creator>
      <pubDate>Sat, 08 Sep 2018 10:57:52 +0000</pubDate>
      <link>https://forem.com/fenetikm/lets-put-the-current-itunes-track-into-the-tmux-status-line-5fk3</link>
      <guid>https://forem.com/fenetikm/lets-put-the-current-itunes-track-into-the-tmux-status-line-5fk3</guid>
      <description>&lt;p&gt;When you go &lt;em&gt;full terminal&lt;/em&gt; it can be nice to know what music is playing for when it really sucks/rocks. Wouldn't it be nice to get something like this into your Tmux status bar:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzqsv4bhmtbo115rsojx3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzqsv4bhmtbo115rsojx3.png" alt="tmux status"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(the answer is &lt;em&gt;yes&lt;/em&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's do this
&lt;/h2&gt;

&lt;p&gt;First you need to get the following into a script file, let's say we put this into &lt;code&gt;~/.config/itunes_status.sh&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class="nv"&gt;ITUNES_TRACK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;osascript &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;
if appIsRunning("iTunes") then
  tell app "iTunes" to get the name of the current track
end if

on appIsRunning(appName)
    tell app "System Events" to (name of processes) contains appName
end appIsRunning
&lt;/span&gt;&lt;span class="no"&gt;EOF

&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ITUNES_TRACK&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nv"&gt;ITUNES_ARTIST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;osascript &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;
  if appIsRunning("iTunes") then
      tell app "iTunes" to get the artist of the current track
  end if

  on appIsRunning(appName)
      tell app "System Events" to (name of processes) contains appName
  end appIsRunning
&lt;/span&gt;&lt;span class="no"&gt;EOF

&lt;/span&gt;  &lt;span class="nv"&gt;TRACK_LEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;ITUNES_TRACK&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$TRACK_LEN&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-gt&lt;/span&gt; 30 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nv"&gt;ITUNES_TRACK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ITUNES_TRACK&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="nt"&gt;-30&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
    ITUNES_TRACK+&lt;span class="o"&gt;=&lt;/span&gt;...
  &lt;span class="k"&gt;fi

  &lt;/span&gt;&lt;span class="nv"&gt;ARTIST_LEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;ITUNES_ARTIST&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ARTIST_LEN&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-gt&lt;/span&gt; 20 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nv"&gt;ITUNES_ARTIST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ITUNES_ARTIST&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="nt"&gt;-20&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
    ITUNES_ARTIST+&lt;span class="o"&gt;=&lt;/span&gt;...
  &lt;span class="k"&gt;fi

  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'#[fg=#99a4bc]♫#[fg=#b4b4b9]'&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ITUNES_TRACK&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s1"&gt;'#[fg=#787882]-#[fg=#b4b4b9]'&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ITUNES_ARTIST&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="nb"&gt;exit
&lt;/span&gt;&lt;span class="k"&gt;else
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"#[fg=#787882]No music playing"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Essentially this does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check if iTunes is running, and if so grab the name of the track&lt;/li&gt;
&lt;li&gt;If we have a track name, also grab the artist&lt;/li&gt;
&lt;li&gt;If the track name is over 30 characters in length, truncate and insert an ellipsis&lt;/li&gt;
&lt;li&gt;If the artist name is over 20 characters in length, do the same&lt;/li&gt;
&lt;li&gt;Output this with some colours and space it out&lt;/li&gt;
&lt;li&gt;Otherwise write "No music playing"&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Insert into the Tmux status bar
&lt;/h2&gt;

&lt;p&gt;Ok, so that's nice an' all but we need to get that into the Tmux status. That can be accomplished by inserting something like the following into your &lt;code&gt;.tmux.conf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; status-right &lt;span class="s2"&gt;"#(~/.config/itunes_status.sh) #[fg=#57575e]│ #[fg=white]%d/%m/%Y %H:%M "&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; as a "bonus" I have also put in the time after the iTunes track (yes, yes, such a generous bonus). If you are wondering what those colour hex values are, they come from the &lt;a href="https://github.com/fenetikm/falcon" rel="noopener noreferrer"&gt;falcon&lt;/a&gt; theme (made by moi). Don't forget that you will need to make this script executable too.&lt;/p&gt;

</description>
      <category>tmux</category>
      <category>bash</category>
      <category>commandline</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
