Category Archives: Command Line

Vim colorscheme tuneup

I hadn’t thought about it for awhile but today I updated by Vim colorscheme for the first time in about two years. In the process I found a few that were notable:









I think this one is based on neon. link




jellybeans blueberry


This is what I decided on. It’s jellybeans with a twist. I put this in my ~/.vimrc for the adjustments:

colorscheme jellybeans
" Jellybeans colorscheme edits (not working)
"let g:jellybeans_overrides = {
"\   'Normal': { 'ctermbg': '242' }, 
"\   'CursorLine': { 'ctermbg': '238' },
highlight Normal     ctermbg=323232
highlight Normal     ctermbg=303030
highlight CursorLine ctermbg=238
highlight Visual     ctermbg=240

Others may have different results though as the theme alters dynamically as per background (mine is #323232 btw).


I got these from a collection today and have put them in the AUR

File backups with sequential numbering

I’ve discovered over the years that sometimes I shouldn’t just dive in and edit a file. That, sometimes, I have grand ideas that aren’t so super. I’ve made edits to files, quit and saved them, then ran them as a script, or read them as a document and said, “Oh boy”. So basically, now, I approach editing files cautiously and if I have any doubt they can be flubbed, then first I will do a backup.

When it is the point where I know a file has to be backed up, first thing I do is check and see if there is a _vault directory. In any location where I had to backup a file previously, I created a _vault directory. After the first time I did this I realized that I was going to have to number these file backups. I reasoned that filename_[0-9][0-9] would be an reasonable format. If an extension was there the entire format would be filename_[0-9][0-9].ext.

As this is something I regularly do, I decided to build a script to make this a bit easier. The usage is basic — I define the file and optionally the destination-directory. If the destination directory remains unspecified then the current directory is used. An example:

$ bckfile file.txt _vault
‘file.txt’ -> ‘_vault/file_01.txt’

The limitation of the script is that files can only contain a period if used for the extension. This is a all but necessary as there would be no easy way to determine in a script if a period in a filename is for an extension or actually a part of the filename.

bckfile can be installed for Arch Linux users as part of the AUR package of my general utility scripts: genscripts-git.

gt — a script to create a gedit scratchpad


I am really lazy with my editors. I have aliases in my shell configuration for gedit and vim to open them as quickly as possible:

alias v="vim -p"
alias sv="sudo vim -p"
alias g="bgcmd gedit"
alias sg="bgcmd gksudo geany"

This is very nice for me because I use my editors quite a bit. One thing I needed though was a command that would create and open a temporary file in gedit. The main reason for this is that, there are times, I don’t know how to name or place the file properly yet. At other times, the reason is I like to have a scratchpad but would rather not lose information if it was just a New File and I forgot about it, or a crash happened.

The bash script

Running geditmp will create and open a file named of the current time (MMDDhhmm) and will be saved in the trash folder. If geditmp is followed by a name (e.g. gt the name will be appended to the current time.


The name is helpful if wanting to dig the file out of the trash folder at a later time.

# (g)edit (t)emp. file. Create/open a temporary file(s).

# Variables
tmp_dir=~/.local/share/Trash/files; [ ! -d "$tmp_dir" ] && mkdir -pv "$tmp_dir"
time="$(date +%m%d%H%M)"

# gedit existence test
hash gedit 2>&- || { echo "Requires program \"gedit\"."; exit 1; }

# Help
if [ $# -lt 1 ] || [ "$1" = -h -o "$1" = --help ]; then
  echo "${0##*/} [name1] [name2*]… — gedit temp. file. Create/open a temporary file(s)."
  exit 1

for name in "$@"; do
  nohup gedit "$tmp_dir"/"$time"-"$name" &> /dev/null &

WTFM (Write the Fine Manual) with Pod2man text-converter

Note: This is a guide from a lightly-proficient manual writer that’s targeted for beginning users: it’s formatting method is easy and conversion method is basic. This method may also be helpful for those that use github because it has rendering support for this method. For a more traditional approach, nixCraft has an article for that.

Because it was the authors first effort to write a man page, talk was that it was good to use Pod2Man. Pod2man is an application that converts text using Plain Old Document (POD) formatting to traditional manual (man) pages. POD markup is easy to do and pod2man is conveniently pre-installed on most Linux distributions (as it is part of the Perl package).

An example

To get a good idea of what to do, here is a basic example demonstrating the formatting (of a fictitious program dr-smile):

=encoding UTF8

=head1 NAME

dr-smile - output platitudes to help to improve one's mood


dr-smile [B<--happy>] [B<--joke>=F<type>]


B<dr-smile> outputs jokes and happy thoughts designed to make one fell F<--better>.  It has the ability to output pleasant thoughts, jokes, good memories, optimistic fortunes...  B<dr-smile> I<isn't> a replacement for a professional doctor, please use responsibly and enjoy.  Additional options are available in the configuration file F</etc/dr-smile.conf>.

=over 4

=item B<-h>B<--happy>

A general happy thought will be output (e.g. C<dr-smile --happy>).

=item B<-j> F<type>B<--joke>=F<type>

A good-sense joke will be told.  The types are: F<knock> and F<oddball>.  Read more in B<jokes(1)>.



There is both text formatting and section formatting that is required for a man page.

Text formatting

All the POD text formatting tags needed to know are as follows:

Bold B<text>
Italic I<text>
Link L< >
Filename F<file>
email E<gt>name@address.comE<lt>

Man pages use two types of formatting (that I’ve ever seen). That are implemented by POD’s bold formatting and PODS filename-or-italic formatting:

Formatting type Used for
POD Bold formatting
  • Program names
  • Options
  • Manuals
POD Filename formatting
POD Italic formatting
  • Files
  • Keywords
  • Emphasis
  • Arguments
  • Occasionally manuals

Section formatting

There are three section tags that are used in pod2man (that I know of). The pod2man manual refers to these as Command Paragraphs and they are: header/category sections, item sub-sections, and “over” sub-sub-sections for additional descriptions of item sections. References to all of these are in the above example.

  • Header/Category sections are the block descriptors and their contents (like NAME, and DESCRIPTION…).
  • Item sections refer to options generally and often override =over sections for their list item.
  • Over sections refer to option descriptions.

General layout structure

Man pages follow a basic (though liberal) structure can be well represented by this:

The name of the command, followed by a one-line description of what it does.
A representative invocation of how to run the command and options it has.
A detailed description of the functioning of the command.
A list of it's options (these are sometimes put in DESCRIPTION).
Some examples of common usage.
List known bugs.
A list of referenced or related commands.
   Specifying the contact information.
   Specifying the copyright information.

The order of categories varies a bit from man page to man page. The first four categories are almost always the same, however the remaining vary a bit. The above layout is an mnemonic aggregate of category order of the man pages that the author has seen.

Convert pod format to manual page

Pod2man usage is basic:

pod2man dr-smile.pod > dr-smile.1

However, these additional options will probably be wanted to be added, plus compression:

pod2man --section=1 --center="dr-smile manual" --name="dr-smile" --release="1.0" dr-smile.pod | gzip > dr-smile.1.gz




xuserrun – Run a command on the currently-active user’s server display

xuserrun is a bash script to run a command on the active server display.  This is primarily necessary if from within another environment  (different user, console, cron, boot script…).  xuserrun gathers DISPLAY and user environmental variables via systemd and passes them on to be able to dothis. xuserrun is designed for use with only a single user server display. Running it is basic:

xuserrun xclock -digital

Tto put out a notification:

xuserrun notify-send "Hello, Dave."

It’s available for Arch users in the AUR and is also downloadable on github.

Audio file encode to a video file

I wanted to convert an MP3 file to a video file to be able to use it on my PS3. The PS3 has an audio player but it doesn’t remember the position. It was an audiobook so it was best for me to convert it to a video file.

# Create video file from audio file.

# Required programs.
if ! hash ffmpeg 2>&- ; then
  echo "Requires program: ffmpeg"; exit 1; fi

# Usage.
if [ $# != 2 ] ; then
    echo "${0##*/} <image> <audio> - create video file from an audio file."
    exit 1; fi

# Files existent test.
if [ ! -f "$1" ] ; then
    echo "non-existent image: "$1""
    exit 1; fi
if [ ! -f "$2" ] ; then
    echo "non-existant audio: "$2""
    exit 1; fi

ffmpeg -f image2 -loop 1 -i "$1" -i "$2" -c:v libx264 -tune stillimage 
  -c:a copy -strict experimental -shortest "$vid_nme"

#ffmpeg -f image2 -loop 1 -i "$1" -i "$2" -c:v libx264 -tune stillimage 
#  -c:a aac -strict experimental -b:a 192k -shortest "$3".mp4

Screencasting Done Easy (Desktop Recording)

I got to test out a good number of screencasting applications and I found a good one, and as usual the easiest was the best. I started with recordMyDesktop.


recordMyDesktop is a basic program that works good. The GTK version has a simple UI that sets a border around the area to be recorded. I has sound recording too.

A minor thing but of note is that the window detection area is off when selecting a windows, but the reason I didn’t use recordMyDesktop was because I found the quality wasn’t that good. It could be because it uses .ogv format, or perhaps it had something to do with my system.

This is and example I did with recordMyDesktop and though it’s enlarged (OpenShot doesn’t have the ability to use the original size) the quality I wanted to be better.


I tried Istanbul and a couple others all with about the same recording results. Istanbul hasn’t been developed in several years and though I got excited about xvidcap it hasn’t been developed in years either. xvidcap grabs screenshots and then concatenates them into a video. I got excited because xvidcap’s preview uses Imagemagick’s animate tool to preview the video and it was real nice. Unfortunately very little works in xvidcap anymore but taking the screenshots. To put them together I used:

fmpeg -i out%04d.xwd -r 15 -vcodec huffyuv test.avi

unfortunately the quality was no better than that of the others.


The great command line tool to encode and decode video ffmpeg can also do screencasts and I read a lot of how people liked it (and I do too). To use it it’s real basic:

ffmpeg -f x11grab -s wxga -i :0.0 -sameq screencast.mpg

The quality isn’t quite what I want it to be, but I’ve seen other people have nice looking screencasts so I think it must be either my video card or my video driver.

This line can be amended some for better quality, performance, and add sound recording. Using the raw, lossless codecs for video and audio improves processor usage for better FPS recording:

ffmpeg -f x11grab -s wxga -i :0.0 -vcodec huffyuv -sameq -acodec pcm_s16le -f alsa -i pulse -ac 2 screencast.avi
  • -s and -i are for size and input. -s will give the dimensions and -i will define the co-ordinates. wxga is a definition of a video resolution standard (available ones are listed in man ffmpeg)
  • -r can be added to define the frame rate. Default is 25 and is good. Only reason really to change it is if frames are dropped during recording (marked with red).
  • -follow_mouse 100 can be added to follow mouse movements. 100 is the border in pixels that must be reached before the area is moved.

ffcast and FFmpeg

ffcast is a program that grabs and passes server dimensions and co-rodinates to other programs. It has built-in support to pass these parameters for some programs including ffmpeg. So the command will now look like this:

ffcast -s ffmpeg -- -vcodec huffyuv -sameq -acodec pcm_s16le -f alsa -i pulse -ac 2 screencast.avi

ffcast’s -s option will prompt for the screen area and then pass the dimensions and co-orodinates to ffmpeg using --.

Now to make this easy, I put this in a bash script, it runs as such:

 screencast <a|f|m|w> - create screencasts (a)rea (f)ull-screen (m)ouse (w)indow

Here’s the bash script:

An example:

Disk and Memory Usage Scripts

At times I like to check my levels of disk and memory usage and it’s more available for me at times for me to do it from the command line. Therefore, I created two scripts for them:

$ devtop 
Filesystem  Size  Used  Avail  Use%  Mounted
/dev/sda1   291G  101G  187G   36%   /
/dev/sda2   166G   38G  121G   24%   /home

$ memtop
PROGRAM          %MEM  #MEM
firefox          14.0  1049.7 MiB
gnome-shell      2.2   165.84 MiB
thunderbird      1.9   143.773 MiB
gedit            0.8   63.8555 MiB
nautilus         0.6   44.9961 MiB
Xorg             0.5   38.5039 MiB
gnome-terminal-  0.3   28.8164 MiB
keepassx         0.3   27.6406 MiB
tracker-extract  0.2   21.1992 MiB

Both script are part of my genscripts-git that is in the Arch Linux User Repository.

Regular videos convert for PSP viewing

I like to put videos on my PSP` to watch later. To be able to remember the options I put this in a bash script.

pspvidconv [-d*] <dir.*> <video(s)> — convert videos to PSP

The PSP allows the creation/use of a supplementary single-depth directory. The directory option (-d) will ask if the user wants to create a new directory, if the answer is no, it will present the existing folders.

# Convert videos to PSP

# Settings
vid_dir=/run/media/$USER/PSP/VIDEO  # For Gnome 3, Gnome 2: /media/PSP/VIDEO
vid_vcd="-vcodec mpeg4 -vtag xvid"  # Video codec: xvid
vid_vcd="-vcodec libx264"           # Video codec: x264
vid_vcd="-vcodec h264"
vid_res=320x240                     # 320x240 for PSP 1001, 480x272 for 2001
vid_vbr=768k                        # Video bit rate, was 1024
vid_vfr=29.97                       # Video frame rate
vid_acd=aac                         # Audio codec to use (libfaac for some)
vid_aab=64k                         # Audio bit rate
vid_aar=48000                       # Audio sampling frequency
vid_aac=2                           # Audio number of channels

# Usage
if [[ -z "$@" ]]; then
  echo "${0##*/} [-d*] <dir.*> <video(s)> — convert videos to PSP"

# Check that PSP is plugged in
if [ ! -d $vid_dir ]; then
  echo "It appears that the PSP is not plugged in, no "$vid_dir"."

# Use sub-directory
if [ "$1" == "-d" ]; then
  while true; do
    read -p " Create a new directory? (y/n): " yn
    case $yn in
      [Yy] )  read -p " Directory name (no spaces): " newdir
              mkdir "$vid_dir" && break 2;;
      [Nn] )  printf " Select PSP VIDEO sub-directory:n"
              select vid_sub in "$vid_dir"/*/
                  test -n "$vid_dir" && break 2
                  echo " Select 1, 2, ..."
                done ;;
      * )     echo " Answer (y)es or (n)o."

# Check if selection(s) exists
for vid in "$@"; do
  if [ ! -f "$vid" ]; then
    echo " Selection ""$vid"" does not exist."

# Convert, save to PSP video directory
for vid in "$@"; do
  vid_out="${vid/:/-}"            # ffmpeg not allowing outputs of ':', '?'
  vid_out="${vid_out/?/}"        #
  #vid_out="${vid_out%.*}"-PSP.mp4 # Append '-PSP' to filename
  # Encode video
  ffmpeg -i file:"$vid" $(printf '%s' "$vid_vcd") -s "$vid_res" -b:v "$vid_vbr" -r "$vid_vfr" -acodec "$vid_acd" -b:a "$vid_aab" -ar "$vid_aar" -ac "$vid_aac" -f psp -strict -2 -y "$vid_dir"/"$vid_out"
  # Create thumbnail
  ffmpeg -i file:"$vid" -f image2 -ss 50 -vframes 1 -s 160x120 "$vid_dir"/"$thm_out"
done && aplay "$fns_snd"

Markdown to WordPress Format

WordPress understand Markdown format now, so this post is obsolete.

When I discovered MarkDown I was in love, it was very nice to discover an easy, clean, well-thought-out markup language. I wanted a way to be able take my detailed notes, have them easy to read, and then to be able post them here on the blog that would be in a nice WordPress format. Yesterday, I wrote about discovering pandoc which enables a person to write in markdown and have it converted to HTML. To be able to use the HTML code created by pandoc in WordPress it needed to be slightly edited and cleaned up. Therefore,… I created a bash script for it.

Example conversion from MarkDown format to WordPress format

It works pretty good. Basically it removes tags for paragraphs (<p>), cleans up code blocks, improves formating, as well as doing a few other things. I haven’t gone through all permutations that pandoc conversion can do so a few thing swill be left out, but otherwise it should work for most things. If anything needs to be added please let me know.

Pandoc-flavored markdown: Perfect!

I’d been looking for a way to convert my notes to webpages. Typically I wrote my notes in .txt form and then went through them and added links, formatting… when I was ready to blog them. Recently, I had asked StackOverflow if I could convert MediaWiki format to HTML. I’m an Administrator for the Arch Wiki so I’m very familiar writing this format. This is when I learned about pandoc. Pandoc’s author describes pandoc as, “If you need to convert files from one markup format into another, pandoc is your swiss-army knife…“.

Plain Text Example

I planned to write my notes in mediawiki format and then convert to HTML, however I’d been using StackOverflow lately and started to learn Markdown Prose and really like it. Markdown’s is designed to be easy to write and read: “Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML)“. Markdown is so easy to write that it makes sense that sites like StackOverflow and GitHub are using it.

Markdown, Markup Languange

Pandoc has extended markdown to use code blocks ```, tables, and a few other things and converting is very basic:

pandoc -o file.htm

I’m in love, I’m in love, I’m in love :), as it will save me a good bit of time in editing/creating Documentation. Tomorrow, I’ll post a bash script to clean up the HTML to be able to put it in a WordPress Blog.


Get every new post delivered to your Inbox.

Join 57 other followers