dotfiles posts

Globbing files including dot-files

Normally globbing for the wildcard * will find all files in a directory except for ones beginning with a .. Sometimes I need to get all files including the dot-files. The pattern .* will find these hidden files, but will also include . and .., referring to the directory and its parent. As I’ve learned in the past, this can be dangerous with commands like rm, (i.e. you running rm -rf .* to remove dot-files will remove more than expected). Today, needing to get all files in a particular path in PHP, I sought a solution. A post on a Perl forum gave me a solution using curly braces: {.??*,.[!.],*}. Braces basically allow multiple comma-separated patterns to be evaluated. The three patterns are:

  1. .??* matches a dot followed by two characters followed by any number of characters.
  2. .[!.] matches a dot followed by a single character that isn’t a dot. This is needed since the previous pattern doesn’t match this case.
  3. * is the normal wildcard glob, matching all non-dot-files.

In PHP, the glob() function requires the GLOB_BRACE flag to use braces. An example might look like: $files = glob($path . '/{.??*,.[!.],*}', GLOB_BRACE);. This did exactly what I wanted.


The Happs

Shell Games

I have been toying with some shell alternatives to bash; fish and zsh. Auto-suggestions were the main draw, though there are other features as well that are nice to have. I especially like the auto-suggestions functionality that fish provides. I have tried to get similar behavior in zsh, but haven’t been able to get something going that doesn’t have problems of some sort. Another feature I like is implicit cd, where you can change to a directory simply by typing its path.

zsh is really configurable and also mostly bash compatible, so I can use the same config files for both. fish requires its own syntax, so I must use separate config files. zsh is also more commonly installed than fish. For these reasons, I would like to move to zsh, but the auto-suggestion problems have led me to go with fish for now.

Dotfiles

My shell experiments have led me to release my dotfiles as open source. I had previously had a much simpler dotfiles setup that I never released openly. My new dotfiles project was mostly written from scratch, with a much more advanced setup script and file organization. I’m maintaining as close to the same configuration as possible between bash, zsh, and fish, and attempt to deal with differences between Linux and Mac OS X.

I have a dotfiles script for setting things up. It symlinks all the relevant files into the home folder. I wrote it in PHP since I know it well and can do OO stuff in it. I have the actual dotfiles plus files they include/reference separated into folders by application / shell. Each folder has a ‘dotfiles.json’ file that defines which files are to be symlinked into the home folder (or other path, if necessary), so that I can have other files mixed in with the dotfiles without the install script paying them any attention.

Looking at some other peoples’ dotfiles, I have improved and added some new functions, aliases, and other features. For instance, I found some neat git log functions that gave some really nice output and modified them to my liking (see my vcs.sh). There were a bunch of other neat things I’ve found but haven’t added.

I put a lot more time into this than I wanted, but am happy with the results. It has brought some improvements to my shell experience and made it easier to share this experience across devices. I still have places I have to log into that I can’t install my dotfiles (namely the servers at work), but for my computers and my server, it has been really nice.

I would like to do something similar with other configuration that isn’t “dotfiles”, such as for Sublime Text and other desktop application. I just have to figure out a good way to do it in an organized fashion. I’m not sure if I’d want that mixed in with my dotfiles or if I’d want a separate repo. Not sure if I’d want a repo per OS either, maybe with a shared repo for things on multiple OS’s.