Funky takes shell functions to the next level by making them easier to define, more flexible, and more interactive.
This packagecouldbe installed using pip like any other Python package (in
fact, see the section below this one for instructions). Given that we only need
this package's entry points (e.g. thefunky
command), however, we recommend
thatpipxbe used instead (replaceSHELL
with eitherbash
orzsh
):
#install and setup pipx
python3 -m pip install --user pipx
python3 -m pipx ensurepath
#install and setup funky
pipx install pyfunky
funky --setup-shell SHELL
To install funky usingpip,run the following commands in your terminal
(replaceSHELL
with eitherbash
orzsh
):
python3 -m pip install --user pyfunky#install funky
funky --setup-shell SHELL#hook funky into your shell
If you don't have pip installed, thisPython installation guidecan guide you through the process.
You can either clone the public repository:
git clone git://github.com/bbugyi200/funky
Or download thetarball:
curl -OL https://github.com/bbugyi200/funky/tarball/master
Once you have a copy of the source, you can install funky by running:
make install
The last thing you need to do is hook funky into your preferred shell, which
can be accomplished with the following command (replaceSHELL
with either
bash
orzsh
):
funky --setup-shell SHELL
Funks are manipulated using thefunky
andgfunky
commands. These commands
have the same user interface. The difference between the two commands is
treated in theLocal vs Globalsection.
Localfunks are stored using a hidden database file that is located in the
same directory where the funk was created. These can be manipulated using the
options described in the demo above (runfunky -h
to see descriptions of
these options). Once created, a local funk can be used just like any other
command or normal funk as long as you are inside of the directory where the
local funk was originally defined.
Globalfunks, on the other hand, are stored in your home directory
(/home/<user>
) and can be used from any directory. Local funks can be used
to override global funk definitions.
Local and global funks can be manipulated (created, removed, edited, renamed,
etc.) by using thefunky
andgfunky
commands, respectively.
Normally when defining a funk, the provided raw definition (the final contents of the temp file) is inserted directly into the generated function definition. However, funky does try to make some alterations to the original funk definition when doing so is convenient. Thesefunky definition shortcutscan make defining funks faster:
A funk definition of the form@./relative/path/to/directory
will be automatically changed to
cd/absolute/path/to/directory/"$@"||return1
A funk definition of the form"Some string here..."
will be automatically changed to
echo"Some string here...""$@"
This allows you to use funks to simulate shell variables viacommand substitution.
This project originally used aliases. The decision to migrate to shell functions was made based on the fact that shell functions are far more capable than aliases. Moreover, there is very little benefit to using aliases over shell functions.
With that said, actual aliases do have one appeal over shell functions. When you use an alias, any
arguments that you pass to it are automatically passed to the command definition (at runtime,
aliases are just substituted with their definitions). For the purpose of emulating this behavior
when it would typically be desired, a funk defined using asingle-linecommand definition
thatdoes NOT already contain argument variables(e.g. does not contain$0
,$1
,...,
$9
,$*
,or$@
) will automatically have the"$@"
special parameter appended to its
definition. This allows for the same automatic argument handling that you would expect from an
alias.
See the officialBash docsfor more information on Bash's special parameters.
With the goal of listing alternative sources of documentation / tutorials, this section will be used to track any articles or blog posts which mention funky:
- 6 Command Line Tools for Productive Programmers(2021-07-23)
- desk- A lightweight workspace manager for the shell.
- smartcd- Alter your bash (or zsh) environment as you cd.
- direnv- is an extension for your shell. It augments existing shells with a new feature that can load and unload environment variables depending on the current directory.
Pull requests are welcome. SeeCONTRIBUTING.mdfor more information.