toys

Tools and things that make my life easier - y'all might like them too

View the Project on GitHub pfuntner/toys

supercd.sh

Purpose

I use this tool as a replacement (or frontend) to cd. It will seek my home directory for a single directory that matches the input regular expression and changes my current working directory to that directory.

Syntax

Syntax: supercd.sh [--verbose] pattern

Options and arguments

| Option | Description | Default | |————————-|————————–|——————————————-| | -v | Enable verbose debugging | Debugging is not enabled |

Examples

Working example

$ # This demonstrates what happens if your don't source the tool
$ supercd.sh foobar
Note: /home/mrbruno/bin/supercd.sh is not sourced
$ # The target does not exist
$ supercd foobar
No matches for foobar
$ # Create the target
$ mkdir ~/foobar
$ # Identify original directory
$ pwd
/home/mrbruno/repos/toys/tmp/20220312091536736347380
$ # Change to destination
$ supercd foobar
/home/mrbruno/foobar
$ # Prove we have changed to the directory
$ pwd
/home/mrbruno/foobar
$

Tool is not sourced

$ supercd.sh foobar
Note: /home/mrbruno/bin/supercd.sh is not sourced
$

No directories match target pattern

$ supercd foobar
No matches for foobar
$

Too many directories match target pattern & refining pattern

$ mkdir ~/foobar ~/foobar-foo
$ supercd foobar
Too many matches for foobar
  /home/mrbruno/foobar-foo
  /home/mrbruno/foobar
$ supercd foobar\$
/home/mrbruno/foobar
$

Verbose output

The tool makes use of a Python script to look at the user’s home directory and locate directories that match the pattern. The Python script will not show errors by default but they can be displayed by using the debugging option:

$ supercd -v foobar
2022-03-12 10:11:19,166 INFO /home/mrbruno/bin/supercd.py:22 listdir('/home/mrbruno/extra/lost+found') error: PermissionError(13, 'Permission denied')
Too many matches for -v foobar
  /home/mrbruno/foobar-foo
  /home/mrbruno/foobar
$

Notes