Bash Script Manager
pbash helps managing a set of bash scripts. It keeps the logic of one file per script, but creates aliases and handle parameter prompt and pipe.
Main features
- bash script run
- parameter prompt
- parameter pass through pipe
- automatic cli command and option from the script
- git support
- possibility to handle several distinct stores
- commands and params autocompletion
Roadmap
- enhanced filter
- test on other platforms
- code cleaning
The application is developped and used on ubuntu 21.10, with python 3.9.7. Any feedback on other platforms is welcomed.
- python3 >=3.6.2,<4.0
- git:
sudo apt install git - nano:
sudo apt install nano
pip install pbashFor an isolated environment with pipx:
pipx install pbashA deb package is available, built using dh-virtualenv. Installing this package will create a new Python virtual environment in opt/venvs. It will then create the symlink usr/bin/pbash pointing to opt/venvs/pbash/bin/pbash.
Note that dh-virtualenv built packages are dependent of python version. Use this only if you have default python version installed:
- ubuntu bionic 18.04: Python 3.6
- ubuntu focal 20.04: Python 3.8
- ubuntu hirsute 21.04: Python 3.9
- ubuntu impish 21.10: Python 3.9
Download latest .deb file from the release page.
sudo dpkg -i pbash_0.1.0_{{os}}_amd64.debInitialisation is required before using the application, to create the working diretory.
pbash initA configuration file .pbashrc is created in the user home directory.
By default, scripts will be stored in ${HOME}/.pbash/ folder.
The --edit option will open configuration file in edit mode.
You can create a new script file.
pbash new --name "${NAME}" --desc "${DESCRIPTION}" --param "${PARAM1}" --param "${PARAM2}"If options are not given, they will be prompted at run.
For param details, see below.
To add a description to the script, add a comment line beginning with #DESC .
#DESC ...To add a param to the script, add a comment line beginning with #PARAM .
#PARAM <name>, <question>, <default>, <always_prompt>Only <name> is required. This value must be strict alphanumeric. The application will automatically create an option --<name> for the cli run command.
<question> is used for cli prompt and option help message. Default is empty string.
<default> is the default value. Default is empty string.
<always_prompt> is used to display prompt even when a default value is given. Set to true if desired. Default is false.
The generic run command calls the corresponding script.
pbash run <name>Options are automatically created based on script informations.
Let's take the below script example.sh
#!/bin/bash
#PARAM user, User
#PARAM message, Which message
read -p "User: " user
read -p "Which message: " message
echo "$user says $message"The script can be run directly through terminal.
It can also be run through pbash : the params will be prompted
pbash run exampleIt can be run with options :
pbash run example --user "Sebastien" --message "Hello World!"Or with piped arguments
(echo "Sebastien"; echo "Hello World!") | pbash run example
# or
cat <(echo "Sebastien") <(echo "Hello World!") | pbash run exampleNote : for piped arguments, all params must be given so that it works
pbash list <filter>Script edition will open the file in default cli editor.
pbash edit <filter>Currently command filter is only done on the script file name.
A future enhancement will provide a better filter functionnality.
pbash <command> <anything> will filter displayed scripts based on anything value (name containing this value).
You can create several stores (config sections). Default store path is ${HOME}/.pbash-${NAME}/
pbash -c "${STORE}" init --new-sectionYou can also select path via the option --path. The folder will be created if it does not exist.
pbash -c "${STORE}" init --new-section --path "${PATH}"All functions can be used for a specific store by using the -c option from pbash application.
pbash -c "${STORE}" new ...
pbash -c "${STORE}" list ...
pbash -c "${STORE}" run ...
# etc.You can initialise a new git repository in store path. It will set automatic git push for every script creation or modification. The git repository needs to be created on your platform before.
A default branch main is created.
pbash -c "${STORE}" init-gitYou can also pass parameter through cli command:
pbash -c "${STORE}" init-git --repo "${REPO}" --user "${USER}" --mail "${EMAIL}" --branch "${BRANCH}"If the git repository already exists, you can restore it in the current store folder by adding the --pull option to init-git command.
It will download the latest commit from main branch. If the branch name is different, you can update it in the config file through pbash init --edit or through --branch option.
When a git repository is enabled, all changes to scripts will be pushed to remote. However, there will never be automatic pull to retrieve potential scripts changes from remote (from other application, computer, user, aso.).
It can be done manually through
pbash -c "${STORE} git pull"
# or
pbash -c "${STORE} git sync" # pull then pushIn case a remote change is done but not pulled, the automatic push on script modification will fail. A manual git sync will be required to merge local and remote.
Application must give a fast access to scripts to be useful.
I personnaly defined shortcuts in my home .bashrc file:
alias pb='pbash -c PRO'
alias pbr='pbash -c PRO run'
alias pbp='pbash -c PERSO'
alias pbpr='pbash -c PERSO run'Requirements
- debhelper:
sudo apt install debhelper - dh-virtualenv
- build
- virtualenv
Commands
poetry install
# build deb
dpkg-buildpackage -us -uc
dpkg-buildpackage -Tclean
# build python package
python3 -m buildPython Libraries
Python Development Libraries
Sébastien Guerri - github page
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also contact me.
Copyright (C) 2022 Sebastien Guerri
pbash is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
pbash is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with pbash. If not, see https://www.gnu.org/licenses/.