I tend to prefer a GUI like Sequel Pro for looking at database data, but since Sequel Pro doesn’t support MySQL 8+ and I haven’t settled on an alternative, I found myself needing to use the CLI. It also can just be faster to use for new or rarely accessed servers or whatever, and is nice and lightweight. However, it wraps query output by default, and with many or wide columns, it can become very hard to read and figure out which data is in which column. Recently, I went looking for something better, and found a StackOverflow question with a couple ways: outputting vertically, and using a pager with a nowrap option set.
Continue reading post "Readable query output in MySQL CLI"cli posts
Looking at Apache logs with command line tools
In my web development career, I have countless times needed to look at Apache logs to figure out or find out about problems with sites, monitor activity, or for various other purposes. I’ve used command line tools to help with this, often looking for strings and counting occurrences. Since I recently needed to create a command string to count unique IP’s connected to a given string in the logs, I thought I’d post about it and a few related useful commands.
Continue reading post "Looking at Apache logs with command line tools"Color shell prompt for available colors
I wanted to make my command line shell prompt to be more noticeable and nicer with some color. I wanted to take advantage of 256 colors when available, but fall back to a simpler color scheme when only 8 colors are available, and to no colors if none are available.
Continue reading post "Color shell prompt for available colors"Midnight Commander
I discovered and played with the CLI text based file browser Midnight Commander this weekend.
Continue reading post "Midnight Commander"Symfony console: Freeing up default short options
I like Symfony’s console component, and use it for much of my command line scripting these days. One thing I dislike is that it takes use of some short option characters for itself. The built in handling of verbosity with -v
is nice and is fairly common in the CLI world, but some, like -h
and -n
, are more varied in use and would be desirable to have for various purposes in my own commands. I decided to remove these defaults in my own console app recently, and will describe how to do so.
Moving folder symlink and trailing slash
It caught me by surprise that if you use mv
on a symlink to a folder and have a trailing slash on the path, it will move the entire original folder rather than the symlink. As a simple example, if you have a symlink ‘symlink’ pointing to the folder ‘original’ and run mv symlink/ new-symlink
, you will end up with ‘original’ now being named ‘new-symlink’ and a symlink ‘symlink’ still pointing to the now non-existant ‘original’. Luckily, merely reversing the arguments will move the folder back to its original location: mv new-symlink symlink/
. The symlink becomes like a magic portal. I probably wouldn’t have run into this if it weren’t for the ‘fish’ shell adding trailing slashes when doing tab completions on folder paths or symlinks to them.
Ooh, SymfonyStyle looks like it’ll make IO a lot easier for Symfony Console (CLI) apps.
Symfony Console
This passed weekend, I released a github project called sy-console. It is a starting point for building command line applications that takes the symfony console component and adds symfony’s dependency injection, configuration handling, plus some other niceties like automatically adding commands from configured directories. If you don’t want those features, you can use the console component directly, but if you do, this takes some of the pain out of setting those up.
Background
I spend a fair amount of time doing things on the command line. I’ve made plenty of command line scripts, mostly in bash. Bash is kind of a pain to work with for anything beyond simple command running scripts. The control structures are a bit limited and have a hard to remember syntax. Data structures are very limited. There’s no such thing as object orientation. Working with Symfony, I really liked the console component, how easy it was to add commands to app/console
, how easy it was to work with arguments, how configuration and services were shared between commands, how it was PHP. I’ve been wanting to use the component for standalone CLI apps for a while now, but was struggling to find how to make it work independently from a full blown Symfony Standard Edition install. I finally found enough resources to get me started and had the requisite free time.