Commandline scripts to quickly navigate through source code files.
In my developement setup I usually work with vim on the commandline. I use these scripts to quickly find files based on a search pattern and open them in vim.
Typical workflow:
-
I want to edit a file from which I know that its filename contains
basemodel. So I entere basemodel -
Since the project has multiple files matching this pattern, I get a list of all matches and can choose the right one:
> (100) 0 server/app/Models/BaseModel.php (100) 1 testserver/app/BaseModel.php Select? -
The selection can be changed with
jandk(down/up) and confirmed with return. Then the selected file opens in vim. -
If I just want to go to the directory that contains this file (to create a new file for example), I use the command
ginstead ofe:g basemodel -
If there is only one match for the pattern, the file is directly opened in the editor.
-
The files are sorted based on rules which can be defined in
e.conf.phpin the project directory. -
Colors highlighting for search results: files that are already open are highlighted in purple, files that have git modifications are highlighted in green.
- PHP 5.6+ (
phpmust be accessible via/usr/bin/env)
-
cd && git clone https://github.com/sebcode/ptool.git -
Add this to
.bashrc:source ~/ptool/shell DEVPATH="$(~/ptool/getpath.php)" DEVSHELL="$DEVPATH/shell" test -f "$DEVSHELL" && { source "$DEVSHELL" } -
Create symlinks (
~/binmust be inPATH)ln -sf "~/ptool/e.php" ~/bin/e ln -sf "~/ptool/ptool.php" ~/bin/ptool
In my setup, all projects have their own directory under ~/dev/. A project
directory usually has the following common contents:
.aliasfile with contains the project alias. For example~/dev/TestProject/.aliasmay containtp. Withpt tpI can switch to that project.- The second line of the
.aliasfile may contain a project description to be displayed in the project list. shell: If this file exists, it will be sourced for every new shell or when you switch to that project. May contain project specific shell aliases for example.todo.txt: Todo file, the commandNopens this file in the editor.e.conf.php: Ruleset for the commandseandg.repocontains a list of the subdirectories that contain the git repositories of the project (newline separated).- One or multiple git repositories.
The ruleset returns a PHP hash array with pattern/priority pairs. Search results are sorted based on the priorities. Example:
<?php return [
'\.php$' => 100,
'\.js' => 90,
'\.mustache' => 80,
'^server/vendor/' => -500,
'^server/app/storage/' => -500,
'^attic/' => -500,
'^tmp/' => -500,
];
pt [project]switch project or show currentego to current project directorye [pattern]search and prompt for file in projecte -ashow all files by score and prompt for filee -gshow all "git status" files by score and promptg [pattern]same as e, but never open file but cd to the directoryNopen notes file for the current project
Sebastian Volland - http://github.com/sebcode
Licensed under the terms of the MIT license (see LICENSE file).