Home

Awesome

Zsh Diractions

Doing Anything, Anywhere, from here

Tag Version Build Status License: MIT Join the chat https://gitter.im/AdrieanKhisbe/diractions

asciicast

Aim

The goal of this plugin is directory indexing, map a short logical/mnemotechnical name to directory to quickly access them, or perform action in them. Thanks to diraction user can perform quick actions on its registered directory, cd into it, ls it, git it, running some command, or refering to them in any command with short variable to denote them.

Hello Diraction

Suppose that I have a hypothetical favdir and mydir directories that i use a alot. Here are a simple scenario: you go in favdir, see what file there is then copy one in mydir using the variable. Then I check it has been copied to the directory with mydir ls, then go in one of mydir subdirectory.

[~]           >> favdir                  # jumping in diraction folder
[~_favdir]    >> ls
                 some-file
[~_favdir]    >> cp some-file $_mydir    # using mydir as a variable
[~_favdir]    >> mydir ls                # calling ls in mydir
                 other-file some-file
[~_favdir]    >> mydir /sub              # jumping in a sub directory of mydir
[~_mydir/sub] >> favdir - git status     # run any command or alias
                 ? someuntrackfile
<!-- §todo: Add some other example, gif of example §see: ho to do them -->

This is just a glimpse of what you can do, if you wanna see more scroll down a bit. Otherwise, go in the terminal and practice. completion is there to help you :)

<!-- §see: inner link document --> <!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->

Table of Contents

<!-- markdown-toc end -->

Usage

Here is some more in depth description about how to use Diractions. Diraction is both a function suite, and the function aliases and vars it will create for you.

Define your own diractions

First step is to define your diractions, associate name to your most used directory.

Use your diraction

Now that you have a diraction it's time to use it. :) Simpliest way is to just type it's name to go in the attached directory. A better way is to type a subcommand along with it

(Sub)Commands

Here are the main commands. Commands that are executed in the context of the diraction:

You can also use the diraction variable in any command. $_mydir will be expanded to the attached directory.

A word about how diraction works: the diraction aliases you create point to a "dispatch function" taking the attached directory as first argument. (For instance diraction mydir pointing to /tmp/mydiris an alias for _diraction-dispatch "/tmp/mydir" )

Completion

diraction aliases support completion.

Completion cover:

Others Diraction Global Commands

and of course, the help command.

Besides every diraction commands accept a -h, --help flag that will get you print help for the specified command.

Installation

If you use package manager, (which I recommend :)), just add the plugin with adrieankhisbe/diractions identifier:

If you want to use the source directly you need to source diractions.plugin.zsh, to support completion you need to add the directory to fpath so that __diraction-dispatch _diraction are in it.

Configuration

Your Diractions

Diractions are not meant to be defined by hand each time, of course there is ways to persist your diractions.

This can be done in two way:

The Diraction Config file

You can store your diraction definition in the DIRACTION_DEF_FILE which is ~/.diractions by default. It just consist in a file having on each line two fields, the name of the diractions, then it's dir You can put comments if you want, shell style #, and use environment variables $HOME or diractions variables $_somepreviouslydefineddir

Here is some sample

  # here are some diraction definition
  ssp  /some/stupid/path
  yasp "$_ssp/yet/another/stupid/path"
<!-- ##### Checkying the config -->

You can check your definition file is correct by using the diraction check config command

The custom hook

Another to customize diractions is to define a function named diraction-personal-config.

This functions is executed by the diraction-load-config if it exists. Definitions in the function will take precedence

Here is some Example:

    diraction-personal-config (){
    # put your config here
    diraction-batch-create <<DIRS
        dir1  /my/path/number1
        yasp  /yet/another/stupid/path
    DIRS
   }

Customs

There is also some variables to customize the behavior of diraction to fit your needs.

Here are the main ones:

History

This plugins started out as some growing tweak in my zsh personal config. First it was named alvar. (as a compaction of alias and variable) It just created an alias to jump in some dir, and a variable to refer to the directory. Later it was extended to perform some action in these directories. Then it was then extracted into is own repo, hence the troubled initial history. With a new repo, he got a new name Diractions (never explain an overobvious pun), and is growing ever since with new functionalities. :)

<!-- Maybe list of feature introduced after 1 will go there? --> <!-- §TODO contribution note --> <!-- Maybe: add version? --> <!-- §maybe analytics? -->

Changelog

Changelog might be consulted in the dedicated file

License

Licensed under MIT.

Notes

If you have any remark, refactor suggestion or you are having some unexpected behavior or bug (soooory), just post an issue ;)

Security Note

(I'm aware of the potential security issues: zsh env/function poisoinning, and evaluated code/injections,... but it's aimed to be used only in interactive mode on your shell so as insecure as a shell bash config. So for now, I would advise not to use it without a glance of the source)