Friday, January 18, 2013

ZSH autocompletion for tmuxinator

I have been using robbyrussell's Oh My Zsh distribution for a few months now and I feel that it's a very good starting point for ZSH newbies. It's a reasonably good set of plugins, themes and configuration files that makes terminal users' life easier.

Yet another handy tool is tmuxinator which makes using/configuring/starting/managing tmux sessions a cinch. However I found that zsh doesn't have autocompletion for tmuxinator command built-in. And all it'd do when I press 'tab' is list out the files and directory in the current directory. It would be cool if I can make it autocomplete command-line options and project names. And that's what I did this morning.

Here is the piece of code you can put it in file called tmuxinator.plugin.zsh inside custom/plugins/tmuxinator/ directory.

_tmux_cmd() {
  # Constants
  local tmuxinator_configs_path
  tmuxinator_configs_path="$HOME/.tmuxinator"

  local a
  read -l a

  num_args=$(echo "$a" | awk '{print NF}')
  last_arg=$(echo "$a" | awk '{print $NF}')

  if [[ $num_args -le 1 ]]; then
    reply=(start open copy delete implode list doctor help version)
  else
    # whether to autocomplete project names
    if [[ -n "$(echo "start open copy delete" | grep -E "\<$last_arg\>")" ]]; then
      reply=(`ls "$tmuxinator_configs_path" | sed 's/\.yml$//' | sed -e :a -e '$!N; s/\n/ /; ta'`)
    fi
  fi
}

compctl -K _tmux_cmd tmuxinator

Here's how the final outcome looks...

When I enter 'tmuxinator ' and press tab, I'll get this

When it is 'tmuxinator open ' (or start or delete or copy), it'd give

Great!

Thursday, January 3, 2013

Split/cut mp3 files using ffmpeg

FFmpeg is a very handy tool. It's hard to find a video/audio encoding/decoding task which it cannot do.  But, with the command-line version one would have to go through the manual page to know about it much better.

Splitting mp3 files is fairly straight forward process.

ffmpeg -i input-file.mp3 -acodec copy -t 00:00:30 -ss 00:02:20 output-file.mp3

This is what I do to extract a 30-second portion (2.20 secs to 2.50 secs) from an mp3 file. Simple!