Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Bash Functions & Aliases for Development

Supercharge your terminal and eliminate context switching. This repository contains the essential Bash functions I use daily to accelerate Python and web development. Quickly spin up new projects, run tests, manage databases, and deploy codeβ€”all with simple, memorable commands. Ideal for developers looking to optimize their CLI efficiency.

Bash Python Django License: MIT

πŸ“‹ Table of Contents

✨ Features

  • Project Scaffolding: Quickly generate Python, Django, and Flask projects with a single command.
  • Virtual Environment Management: Automate the creation and activation of Python virtual environments.
  • Django CLI Tool: A comprehensive helper (dj) for all common Django tasks (runserver, migrations, testing, etc.).
  • Code Quality: Integrate flake8 and autopep8 for automatic code style checking and formatting.
  • Git Automation: Add, commit, and push changes with one command.
  • Database Management: Start, stop, and check the status of MySQL/PostgreSQL servers.
  • File Templates: Generate pre-configured Python and HTML template files.

βš™οΈ Prerequisites

Ensure you have the following installed on your system:

  • Bash (v4.0+)
  • Python 3 and pip
  • Virtualenv (python3 -m pip install virtualenv)
  • Django (Will be installed by the dj tool, but required for its functions)
  • Flake8 & Autopep8 (pip install flake8 autopep8)
  • Pytest (pip install pytest)
  • JSON Server (for the json function, install via npm: npm install -g json-server)
  • Systemd (for database management functions on Linux)

πŸ“₯ Installation

  1. Clone or download the repository.

    git clone <your-repo-url>
    cd bash-development-utils
  2. Source the functions file in your .bashrc. The most maintainable method is to source the file externally. Add the following line to the end of your ~/.bashrc file:

    # Replace /path/to/ with the actual path to the file.
    if [ -f ~/bash-development-utils/bash_functions.txt ]; then
        source ~/bash-development-utils/bash_functions.txt
    fi

    For a cleaner setup, you can rename bash_functions.txt to .bash_functions and move it to your home directory:

    cp bash_functions.txt ~/.bash_functions

    Then source it from your ~/.bashrc like this:

    # Source custom bash functions
    if [ -f ~/.bash_functions ]; then
        source ~/.bash_functions
    fi
  3. Reload your Bash configuration.

    source ~/.bashrc

πŸš€ Usage

Once installed, you can use any of the functions below in your terminal.

Core Functions

Command Description
list Displays a categorized list of all available custom functions and aliases.

Python Development

Command Description
pynew <project_name> Creates a complete Python project structure with src/, tests/, docs/, and a virtual environment.
mkpython <project_name> Creates a minimal Python project with a virtual environment.
activenv Activates the virtual environment in the current directory.
addenv Creates a virtual environment in the current directory.
req Installs Python dependencies from requirements.txt in the active virtual environment.
pp Runs main.py in the current directory.
pa Runs app.py in the current directory.
npy <filename.py> Creates a new Python file with a helpful template and makes it executable.
pstyle <file/dir> Checks code style with flake8 and automatically formats it with autopep8.
ptest Runs tests using pytest.
findfunc <function_name> Searches for a function name across all .py files in the current directory.
mkreq Generates a requirements.txt file from the currently installed packages in the virtual environment.
pyig Generates a comprehensive .gitignore file for Python projects.

Django Management (dj)

The dj function is a powerful CLI tool for managing Django projects.

Command Description
dj new <project_name> Creates a new Django project, virtual environment, and initializes Git.
dj app <app_name> Creates a new app within the current Django project.
dj run Starts the Django development server.
dj -m or --migrate Applies database migrations.
dj -mm or --makemigrations Creates new migration files.
dj -su or --superuser Creates a superuser.
dj test Runs the project's test suite.
dj testcov Runs tests with coverage reporting.
dj shell Opens the Django shell.
dj -c or --check Checks the project for common problems.
dj -cs or --collect Collects static files.
dj -h or --help Shows the full help message.

Web & Database Utilities

Command Description
flask <project_name> Scaffolds a basic Flask project structure.
nht <filename.html> Creates a basic HTML5 template file.
dbstart <mysql/postgresql> Starts a database server (requires sudo).
dbstop <mysql/postgresql> Stops a database server (requires sudo).
dbstatus <mysql/postgresql> Checks the status of a database server.
json <file.json> Serves a JSON file via json-server for API mocking.

Git Automation

Command Description
gitit "commit message" Executes git add ., git commit -m "message", and git push origin main in sequence.

πŸ”€ Custom Aliases

The list command also shows useful aliases, including:

  • cleansub / cleanweb: Organize subtitle or HTML files.
  • md: View Markdown files in the terminal.
  • bat: Use batcat for syntax-highlighted file viewing.
  • warp/warpd/warps: Manage Cloudflare WARP VPN connection.
  • mm / ma: Edit main.py or app.py with the micro editor.
  • sv2 / ev2: Start and stop the v2rayA service.
  • ll: List directory contents respecting .gitignore.
  • e.: Open the current directory in ranger.
  • ebash/ebashf/etc.: Quick commands to edit Bash configuration files.

🀝 Contributing

Contributions are welcome! Feel free to fork this repository and submit Pull Requests to add new functions, improve existing ones, or enhance the documentation.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFunction)
  3. Commit your Changes (git commit -m 'Add some AmazingFunction')
  4. Push to the Branch (git push origin feature/AmazingFunction)
  5. Open a Pull Request

πŸ“œ License

This project is distributed under the MIT License. See the LICENSE file for more information.


Tags: bash productivity python django flask automation developer-tools cli git

About

My curated set of Bash functions to supercharge a Python developer's workflow.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages