Use map
and filter
in your shell.
This tool was written for learning and is not optimized for speed or compatibility.
Tested with Zsh and Bash 3/4/5.
Quick Start:
map --help
andfilter --help
for usage and examples- See COOKBOOK.md for real-world examples and recipes
$ find .
./README.md
./Makefile
$ find . | map abspath
/Users/simon/repos/functional-shell/README.md
/Users/simon/repos/functional-shell/Makefile
$ find . | map abspath | map basename
README.md
Makefile
$ find . | map prepend 'file: '
file: ./README.md
file: ./Makefile
$ find . | filter contains md
./README.md
$ find . | filter contains md | map abspath
/Users/simon/repos/functional-shell/README.md
$ seq 3 | map add 100
101
102
103
Install to your user directory (recommended):
/bin/bash <(curl -s https://raw.githubusercontent.com/simeg/functional-shell/master/install.sh)
This installs to ~/.local/bin
and ~/.local/lib/functional-shell
. Make sure ~/.local/bin
is in your PATH:
export PATH="$HOME/.local/bin:$PATH"
System-wide installation:
curl -s https://raw.githubusercontent.com/simeg/functional-shell/master/install.sh | bash -s -- --system
Custom prefix:
curl -s https://raw.githubusercontent.com/simeg/functional-shell/master/install.sh | bash -s -- --prefix /usr/local
Manual installation:
git clone https://github.com/simeg/functional-shell.git
cd functional-shell
./install.sh --help # See all options
Tab completion is automatically installed and provides:
- Operation suggestions:
map <TAB>
β shows available operations - Contextual help: Shows operation descriptions
- Works with both bash and zsh
# If installed via install.sh
curl -fsSL https://raw.githubusercontent.com/simeg/functional-shell/master/scripts/uninstall.sh | bash
# If installed from source
make uninstall
abspath :: Path β Path
dirname :: Path β Path
basename :: Path β Path
is_dir :: Path β Bool
is_file :: Path β Bool
is_link :: Path β Bool
is_executable :: Path β Bool
exists :: Path β Bool
has_ext ext :: Path β Bool
strip_ext :: Path β String
replace_ext new_ext :: Path β Path
split_ext :: Path β Array
non_empty :: * β Bool
add num :: Int β Int
sub num :: Int β Int
mul num :: Int β Int
even :: Int β Bool
odd :: Int β Bool
pow num :: Int β Int
eq other :: * β Bool
equal other :: * β Bool
equals other :: * β Bool
ne other :: * β Bool
not_eq other :: * β Bool
not_equals other :: * β Bool
ge i :: Int β Bool
greater_equals i :: Int β Bool
gt i :: Int β Bool
greater_than i :: Int β Bool
le i :: Int β Bool
less_equals i :: Int β Bool
lt i :: Int β Bool
less_than i :: Int β Bool
reverse :: String β String
append suffix :: String β String
strip :: String β String
substr start end :: String β String
take count :: String β String
to_lower :: String β String
to_upper :: String β String
replace old new :: String β String
prepend prefix :: String β String
capitalize :: String β String
drop count :: String β String
split delimiter :: String β Array
duplicate :: String β Array
contains substring :: String β Bool
starts_with pattern :: String β Bool
ends_with pattern :: String β Bool
len :: String β Int
length :: String β Int
id :: * β *
identity :: * β *
Functional-shell has been optimized for performance with modern bash built-ins and minimal subprocess overhead.
Run the comprehensive performance benchmark:
make benchmark
# or
./benchmark.sh
This script tests all operations across different categories and input sizes (1K-10K lines), providing:
- Individual operation timing
- Performance analysis by category
- Input size scaling tests
- Optimization recommendations
Fast Operations (~0.01-0.2s for 10K lines):
- Arithmetic:
add
,sub
,mul
(bash built-in arithmetic) - File operations:
basename
,dirname
(bash parameter expansion) - Simple operations:
id
,len
,append
,prepend
Medium Operations (~0.5-2s for 10K lines):
- String operations:
to_upper
,to_lower
,reverse
(usingtr
/rev
) - Comparisons:
eq
,gt
,lt
variants
Slower Operations (>2s for 10K lines):
- Complex string operations:
substr
,replace
(complex parsing) - File system checks:
is_file
,exists
(system calls) - Mathematical:
pow
(computational complexity)
- Bash 3.2 Compatibility: Uses
tr
for case conversion instead of${var^^}
syntax - Subprocess Minimization: Operations use bash built-ins where possible
- Large Datasets: For >50K lines, consider native tools like
awk
,sed
,tr
- Filter vs Map: Filter operations have slight overhead due to boolean result checking
For reference, native tools are typically faster for specialized tasks:
# For case conversion
echo "text" | tr '[:lower:]' '[:upper:]' # vs map to_upper
# For filtering numbers
seq 1 100 | awk 'NR % 2 == 0' # vs filter even
Functional-shell provides a consistent, composable interface at the cost of some performance compared to specialized tools.