NAME

short - Manage short directory symlinks

VERSION

This document describes version 0.14 of short (from Perl distribution App-short), released on 2017-07-10.

SYNOPSIS

Assuming you put your projects/repositories under ~/repos, e.g.:

 perl-Text-ANSITable/
 cpan-Perinci-Sub-Exporter/
 p5-Data-Format-Pretty/
 p5-Data-Format-Pretty-HTML/
 p5-Data-Format-Pretty-JSON/
 some-other-project/
 yet-another-project/

and you want to maintain a list of short symlink names in ~/proj, e.g.:

 ansitable -> ../repos/perl-Text-ANSITable
 perisexp -> ../repos/cpan-Perinci-Sub-Exporter
 dfp -> ../repos/p5-Data-Format-Pretty
 dfph -> ../repos/p5-Data-Format-Pretty-HTML
 dfpj -> ../repos/p5-Data-Format-Pretty-JSON

First, create ~/.config/short.conf:

 long_dir  = ~/repos
 short_dir = ~/proj

 ; only include dirs in long_dir matching these regexes
 long_include = ["^perl-", "^p5-", "^cpan-"]

Then you can:

 # list all short names
 % short ls
 % short ls -l; # more detail

 # list all long names
 % short long
 % short long -l

 # list long names which do not have short symlinks yet
 % short missing
 % short missing -l

 # add short name
 % short add p5-Data-Format-Pretty-Console dfpc

 # return long directory (return undef when short name is unknown)
 % short get dfpc
 /home/ujang/repos/p5-Data-Format-Pretty-Console
 % cd `short get dfpc`

Pro-tip: install this bash function to be able to cd quickly to a short directory (tab completion is also provided):

 # function definition
 cds ()
 {
     if [[ "$1" = "" ]]; then echo "Please specify a short name"; return; fi
     local dir=`short get "$1"`
     if [[ "$dir" = "" ]]; then echo "Failed"; else cd "$dir"; fi
 }
 
 # tab completion
 _cds ()
 {
     local cur=${COMP_WORDS[COMP_CWORD]}
     COMPREPLY=( `COMP_LINE="short get $cur" COMP_POINT=$[10+${#cur}] short` )
 }
 
 # activate tab completion
 complete -F _cds cds

Afterwards, you can:

 % cds ans<tab>
 % cds ansitable

DESCRIPTION

NOTE: EARLY IMPLEMENTATION, MORE SUBCOMMANDS AND OPTIONS WILL BE ADDED IN THE FUTURE.

Perl project directories (typically CPAN distributions, Git repositories) usually have rather long names, e.g.:

 perl-Text-ANSITable
 cpan-Perinci-Sub-Exporter
 p5-Data-Format-Pretty
 p5-Data-Format-Pretty-HTML
 p5-Data-Format-Pretty-JSON

In some places short single-word aliases are useful, e.g.:

 ansitable
 perisexp
 dfp
 dfph
 dfpj

Where is this useful? First, when typing or cd-ing the directory names (even though there is shell tab completion, we still often have to type the names):

 % cd proj/dfph; # shorter than: cd repos/p5-Data-Format-Pretty-HTML

Second is when referring in internal documents. Writing and reading the short names like dfpj is much more convenient and faster (as long as they are already familiar) than having to explicitly write Data::Format::Pretty::JSON every time. Especially if you, like me, have hundreds of projects and have to cross-reference one another when writing documentation, for example when writing todo lists:

 * TODO dfp: Add support for more environment variables
 * TODO perisexp: Support Sub::Exporter-style interface
 * TODO ansitable: Optimize performance

The short names are implemented as just symlinks to the real names. And this script is just a simple CLI tool to help you manage them. I've used symlinks since at least 2002-2003, and have only started writing this tool in March 2015.

SUBCOMMANDS

add

duplicate

get

long

ls

missing

rm

OPTIONS

* marks required options.

Common options

--config-path=filename

Set path to configuration file.

Can be specified multiple times.

--config-profile=s

Set configuration profile to use.

--format=s

Choose output format, e.g. json, text.

Default value:

 undef
--help, -h, -?

Display help message and exit.

--json

Set output format to json.

--naked-res

When outputing as JSON, strip result envelope.

Default value:

 0

By default, when outputing as JSON, the full enveloped result is returned, e.g.:

    [200,"OK",[1,2,3],{"func.extra"=>4}]

The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use `--naked-res` so you just get:

    [1,2,3]
--no-config

Do not use any configuration file.

--no-env

Do not read environment for default options.

--subcommands

List available subcommands.

--version, -v

Display program's version and exit.

Options for subcommand add

--long-dir=s*, -L
--long-include-json=s

See --long-include.

--long-include=s@

Can be specified multiple times.

--long=s*
--short-dir=s*, -S
--short=s*

Options for subcommand duplicate

--detail, -l
--long-dir=s*, -L
--long-include-json=s

See --long-include.

--long-include=s@

Can be specified multiple times.

--short-dir=s*, -S

Options for subcommand get

--long-dir=s*, -L
--long-include-json=s

See --long-include.

--long-include=s@

Can be specified multiple times.

--short-dir=s*, -S
--short=s*

Options for subcommand long

--detail, -l
--long-dir=s*, -L
--long-include-json=s

See --long-include.

--long-include=s@

Can be specified multiple times.

--short-dir=s*, -S

Options for subcommand ls

--broken
--detail, -l
--long-dir=s*, -L
--long-include-json=s

See --long-include.

--long-include=s@

Can be specified multiple times.

--query=s
--short-dir=s*, -S

Options for subcommand missing

--detail, -l
--long-dir=s*, -L
--long-include-json=s

See --long-include.

--long-include=s@

Can be specified multiple times.

--short-dir=s*, -S

Options for subcommand rm

--long-dir=s*, -L
--long-include-json=s

See --long-include.

--long-include=s@

Can be specified multiple times.

--short-dir=s*, -S
--short-json=s

See --short.

--short=s@*

Can be specified multiple times.

COMPLETION

This script has shell tab completion capability with support for several shells.

bash

To activate bash completion for this script, put:

 complete -C short short

in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.

It is recommended, however, that you install modules using cpanm-shcompgen which can activate shell completion for scripts immediately.

tcsh

To activate tcsh completion for this script, put:

 complete short 'p/*/`short`/'

in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.

It is also recommended to install shcompgen (see above).

other shells

For fish and zsh, install shcompgen as described above.

CONFIGURATION FILE

This script can read configuration files. Configuration files are in the format of IOD, which is basically INI with some extra features.

By default, these names are searched for configuration filenames (can be changed using --config-path): ~/.config/short.conf, ~/short.conf, or /etc/short.conf.

All found files will be read and merged.

To disable searching for configuration files, pass --no-config.

To put configuration for a certain subcommand only, use a section name like [subcommand=NAME] or [SOMESECTION subcommand=NAME].

You can put multiple profiles in a single file by using section names like [profile=SOMENAME] or [SOMESECTION profile=SOMENAME] or [subcommand=SUBCOMMAND_NAME profile=SOMENAME] or [SOMESECTION subcommand=SUBCOMMAND_NAME profile=SOMENAME]. Those sections will only be read if you specify the matching --config-profile SOMENAME.

You can also put configuration for multiple programs inside a single file, and use filter program=NAME in section names, e.g. [program=NAME ...] or [SOMESECTION program=NAME]. The section will then only be used when the reading program matches.

Finally, you can filter a section by environment variable using the filter env=CONDITION in section names. For example if you only want a section to be read if a certain environment variable is true: [env=SOMEVAR ...] or [SOMESECTION env=SOMEVAR ...]. If you only want a section to be read when the value of an environment variable has value equals something: [env=HOSTNAME=blink ...] or [SOMESECTION env=HOSTNAME=blink ...]. If you only want a section to be read when the value of an environment variable does not equal something: [env=HOSTNAME!=blink ...] or [SOMESECTION env=HOSTNAME!=blink ...]. If you only want a section to be read when an environment variable contains something: [env=HOSTNAME*=server ...] or [SOMESECTION env=HOSTNAME*=server ...]. Note that currently due to simplistic parsing, there must not be any whitespace in the value being compared because it marks the beginning of a new section filter or section name.

List of available configuration parameters:

Common for all subcommands

 format (see --format)
 naked_res (see --naked-res)

Configuration for subcommand add

 long (see --long)
 long_dir (see --long-dir)
 long_include (see --long-include)
 short (see --short)
 short_dir (see --short-dir)

Configuration for subcommand duplicate

 detail (see --detail)
 long_dir (see --long-dir)
 long_include (see --long-include)
 short_dir (see --short-dir)

Configuration for subcommand get

 long_dir (see --long-dir)
 long_include (see --long-include)
 short (see --short)
 short_dir (see --short-dir)

Configuration for subcommand long

 detail (see --detail)
 long_dir (see --long-dir)
 long_include (see --long-include)
 short_dir (see --short-dir)

Configuration for subcommand ls

 broken (see --broken)
 detail (see --detail)
 long_dir (see --long-dir)
 long_include (see --long-include)
 query (see --query)
 short_dir (see --short-dir)

Configuration for subcommand missing

 detail (see --detail)
 long_dir (see --long-dir)
 long_include (see --long-include)
 short_dir (see --short-dir)

Configuration for subcommand rm

 long_dir (see --long-dir)
 long_include (see --long-include)
 short (see --short)
 short_dir (see --short-dir)

ENVIRONMENT

SHORT_OPT => str

Specify additional command-line options.

FILES

~/.config/short.conf

~/short.conf

/etc/short.conf

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/App-short.

SOURCE

Source repository is at https://github.com/perlancar/perl-App-short.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-short

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017, 2015 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.