Skip to content

Commit 0c660a3

Browse files
authored
Merge pull request #2308 from seefood/gaelic-plugins
2 parents 3cbecfc + 2665ca8 commit 0c660a3

31 files changed

+596
-348
lines changed

CLAUDE.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
Bash-it is a collection of community Bash commands and scripts for Bash 3.2+, providing a framework for aliases, themes, plugins, and completions. It's structured as a modular system where components can be individually enabled or disabled.
8+
9+
## Architecture
10+
11+
### Core Components
12+
13+
- **bash_it.sh**: Main entry point that initializes the framework
14+
- **lib/**: Core libraries providing utilities, logging, helpers, and appearance functions
15+
- **scripts/reloader.bash**: Component loader that sources enabled components
16+
- **install.sh**: Installation script with interactive and silent modes
17+
- **enabled/**: Symlinks to active components from available/ directories
18+
19+
### Component Types
20+
21+
1. **Aliases** (`aliases/available/`): Command shortcuts and convenience functions
22+
2. **Plugins** (`plugins/available/`): Extended functionality and integrations
23+
3. **Completions** (`completion/available/`): Tab completion definitions
24+
4. **Themes** (`themes/`): Prompt customizations and visual styles
25+
26+
### Loading Order
27+
28+
1. Libraries (except appearance)
29+
2. Global enabled directory
30+
3. Enabled aliases, plugins, completions
31+
4. Theme files (if BASH_IT_THEME is set)
32+
5. Custom files from BASH_IT_CUSTOM directory
33+
34+
## Development Commands
35+
36+
### Testing
37+
```bash
38+
# Run all tests using BATS (Bash Automated Testing System)
39+
test/run
40+
41+
# Run specific test suites
42+
test/run test/bash_it test/completion test/plugins
43+
44+
# Tests require git submodules to be initialized
45+
git submodule init && git submodule update
46+
```
47+
48+
### Linting and Code Quality
49+
50+
The project uses a gradual pre-commit system implementation via `clean_files.txt` allow-list:
51+
52+
```bash
53+
# Run pre-commit hooks only on allow-listed clean files
54+
./lint_clean_files.sh
55+
56+
# Run pre-commit hooks on all files (for testing new coverage)
57+
pre-commit run --all-files
58+
59+
# Manual shellcheck on bash files
60+
shellcheck **/*.bash
61+
62+
# Format shell scripts
63+
shfmt -w **/*.bash
64+
```
65+
66+
**Gradual Linting System**:
67+
- `clean_files.txt`: Allow-list of files/directories that pass all linting rules
68+
- `lint_clean_files.sh`: Runs pre-commit hooks only on allow-listed files
69+
- When modifying files NOT in `clean_files.txt`, ensure they pass linting before adding them to the allow-list
70+
- Before creating a PR, add newly cleaned files to `clean_files.txt` to expand coverage
71+
- This system allows gradual improvement of code quality across the large codebase
72+
73+
**Vendor Directory Policy**:
74+
- Files in `vendor/` are treated as immutable external dependencies
75+
- Pre-commit hooks exclude vendor files via `.pre-commit-config.yaml` global exclude pattern
76+
- `clean_files.txt` does not include vendor shell scripts, only `.gitattributes`
77+
- CI and local linting will skip vendor files entirely
78+
79+
### Component Management
80+
```bash
81+
# Enable/disable components
82+
bash-it enable alias git
83+
bash-it enable plugin history
84+
bash-it enable completion docker
85+
86+
# Show available components
87+
bash-it show aliases
88+
bash-it show plugins
89+
bash-it show completions
90+
91+
# Search components
92+
bash-it search docker
93+
```
94+
95+
## Key Configuration
96+
97+
### Environment Variables
98+
- `BASH_IT`: Base directory path
99+
- `BASH_IT_THEME`: Active theme name
100+
- `BASH_IT_CUSTOM`: Custom components directory
101+
- `BASH_IT_LOG_PREFIX`: Logging prefix for debug output
102+
103+
### File Structure Conventions
104+
- Available components: `{type}/available/{name}.{type}.bash`
105+
- Enabled components: `{type}/enabled/{name}.{type}.bash` (symlinks)
106+
- Custom components: `custom/{name}.bash`
107+
- Themes: `themes/{name}/`
108+
109+
## Development Guidelines
110+
111+
### Component Development
112+
- Use composure metadata: `about`, `group`, `author`, `example`
113+
- Follow naming convention: `{name}.{type}.bash`
114+
- Test components before submitting
115+
- Components should be modular and not conflict with others
116+
117+
### Testing Components
118+
- Each component type has dedicated test files in `test/`
119+
- Use BATS framework for shell script testing
120+
- Test files follow pattern: `{component}.bats`
121+
122+
### Code Standards
123+
- Use shellcheck for linting
124+
- Follow existing code style in the repository
125+
- Add appropriate metadata using composure functions
126+
- Components should handle missing dependencies gracefully

aliases/available/general.aliases.bash

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
# shellcheck source-path=SCRIPTDIR
33
about-alias 'general aliases'
44

5+
if command ls --color -d . &> /dev/null; then
6+
alias ls='ls --color=auto'
7+
# BSD `ls` doesn't need an argument (`-G`) when `$CLICOLOR` is set.
8+
fi
9+
10+
# List directory contents
11+
alias sl=ls
12+
alias la='ls -AF' # Compact view, show hidden
13+
alias ll='ls -Al'
14+
alias l='ls -A'
15+
alias l1='ls -1'
16+
alias lf='ls -F'
17+
518
alias _='sudo'
619

720
# colored grep
@@ -58,7 +71,12 @@ alias rd='rmdir'
5871
alias rmrf='rm -rf'
5972

6073
# Shorten extract
61-
alias xt='extract'
74+
_command_exists 'extract' \
75+
&& alias xt='extract'
76+
77+
# sudo editors
78+
alias svim='sudo "${VISUAL:-vim}"'
79+
alias snano='sudo "${ALTERNATE_EDITOR:-nano}"'
6280

6381
# Display whatever file is regular file or folder
6482
function catt() {

bash_it.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ _bash_it_library_finalize_hook=()
2222
# We need to load logging module early in order to be able to log
2323
source "${BASH_IT}/lib/log.bash"
2424

25-
# libraries, but skip appearance (themes) for now
26-
_log_debug "Loading libraries(except appearance)..."
27-
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
25+
# Load libraries
26+
_log_debug "Loading libraries..."
2827
for _bash_it_main_file_lib in "${BASH_IT}/lib"/*.bash; do
29-
[[ "$_bash_it_main_file_lib" == "$APPEARANCE_LIB" ]] && continue
3028
_bash-it-log-prefix-by-path "${_bash_it_main_file_lib}"
3129
_log_debug "Loading library file..."
3230
# shellcheck disable=SC1090
@@ -55,10 +53,14 @@ if [[ -n "${BASH_IT_THEME:-}" ]]; then
5553
source "${BASH_IT}/themes/base.theme.bash"
5654

5755
BASH_IT_LOG_PREFIX="lib: appearance: "
58-
# appearance (themes) now, after all dependencies
59-
# shellcheck source=SCRIPTDIR/lib/appearance.bash
60-
source "$APPEARANCE_LIB"
61-
BASH_IT_LOG_PREFIX="core: main: "
56+
# shellcheck disable=SC1090
57+
if [[ -f "${BASH_IT_THEME}" ]]; then
58+
source "${BASH_IT_THEME}"
59+
elif [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then
60+
source "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash"
61+
elif [[ -f "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then
62+
source "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash"
63+
fi
6264
fi
6365

6466
_log_debug "Loading custom aliases, completion, plugins..."

clean_files.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ hooks/
2323
lib/
2424
plugins/
2525
scripts/
26+
template/
2627
test/
2728

2829
# root files
@@ -32,6 +33,7 @@ bash_it.sh
3233
clean_files.txt
3334
install.sh
3435
lint_clean_files.sh
36+
uninstall.sh
3537

3638
# themes
3739
#

docs/installation.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Installation
66

77
#. Check out a clone of this repo to a location of your choice, such as
88
``git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it``
9-
#. Run ``~/.bash_it/install.sh`` (it automatically backs up your ``~/.bash_profile`` or ``~/.bashrc``\ , depending on your OS)
10-
#. Edit your modified config (\ ``~/.bash_profile`` or ``~/.bashrc``\ ) file in order to customize Bash-it.
9+
#. Run ``~/.bash_it/install.sh`` (it automatically backs up your ``~/.bashrc``\ )
10+
#. Edit your modified config (\ ``~/.bashrc``\ ) file in order to customize Bash-it.
1111
#. Check out available aliases, completions, and plugins and enable the ones you want to use (see the next section for more details).
1212

1313
Install Options
@@ -18,7 +18,7 @@ The install script can take the following options:
1818

1919
* ``--interactive``\ : Asks the user which aliases, completions and plugins to enable.
2020
* ``--silent``\ : Ask nothing and install using default settings.
21-
* ``--no-modify-config``\ : Do not modify the existing config file (\ ``~/.bash_profile`` or ``~/.bashrc``\ ).
21+
* ``--no-modify-config``\ : Do not modify the existing config file (\ ``~/.bashrc``\ ).
2222
* ``--append-to-config``\ : Back up existing config file and append bash-it templates at the end.
2323

2424
When run without the ``--interactive`` switch, Bash-it only enables a sane default set of functionality to keep your shell clean and to avoid issues with missing dependencies.
@@ -28,16 +28,14 @@ When you run without the ``--no-modify-config`` switch, the Bash-it installer au
2828
Use the ``--no-modify-config`` switch to avoid unwanted modifications, e.g. if your Bash config file already contains the code that loads Bash-it.
2929

3030
**NOTE**\ : Keep in mind how Bash loads its configuration files,
31-
``.bash_profile`` for login shells (and in macOS in terminal emulators like `Terminal.app <http://www.apple.com/osx/apps/>`_ or
32-
`iTerm2 <https://www.iterm2.com/>`_\ ) and ``.bashrc`` for interactive shells (default mode in most of the GNU/Linux terminal emulators),
33-
to ensure that Bash-it is loaded correctly.
31+
``.bash_profile`` for login shells and ``.bashrc`` for interactive shells, to ensure that Bash-it is loaded correctly.
3432
A good "practice" is sourcing ``.bashrc`` into ``.bash_profile`` to keep things working in all the scenarios.
3533
To achieve this, you can add this snippet in your ``.bash_profile``\ :
3634

3735
.. code-block::
3836
39-
if [ -f ~/.bashrc ]; then
40-
. ~/.bashrc
37+
if [[ $- == *"i"* && -f ~/.bashrc ]]; then
38+
source ~/.bashrc
4139
fi
4240
4341
Refer to the official `Bash documentation <https://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files>`_ to get more info.

docs/themes-list/atomic.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Automatically via terminal
3636

3737

3838
#. You can install the theme automatically using the ``sed`` command from your Linux or OSX Terminal.
39-
#. On macOS, the ~/.bash_profile is used, not the ~/.bashrc.
4039
#. For installation on windows you should use `\ ``Git-Bash`` <https://git-for-windows.github.io/>`_ or make sure the terminal emulator you use (ej: cygwin, mintty, etc) has the ``sed`` command installed.
4140

4241
Command to execute For Windows and Linux:
@@ -51,7 +50,7 @@ Command to execute for macOS:
5150
.. code-block:: bash
5251
5352
# Set the "atomic" theme replacing the theme you are using of bash-it
54-
sed -i '' 's/'"$BASH_IT_THEME"'/atomic/g' ~/.bash_profile
53+
sed -i '' 's/'"$BASH_IT_THEME"'/atomic/g' ~/.bashrc
5554
5655
Features
5756
--------

docs/themes-list/powerline-base.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ all powerline themes.
88

99
**IMPORTANT:** This theme requires that `a font with the Powerline symbols <https://github.com/powerline/fonts>`_ needs to be used in your terminal emulator, otherwise the prompt won't be displayed correctly, i.e. some of the additional icons and characters will be missing. Please follow your operating system's instructions to install one of the fonts from the above link and select it in your terminal emulator.
1010

11-
**NOTICE:** The default behavior of this theme assumes that you have sudo privileges on your workstation. If that is not the case (e.g. if you are running on a corporate network where ``sudo`` usage is tracked), you can set the flag 'export THEME_CHECK_SUDO=false' in your ``~/.bashrc`` or ``~/.bash_profile`` to disable the Powerline theme's ``sudo`` check. This will apply to all ``powerline*`` themes.
11+
**NOTICE:** The default behavior of this theme assumes that you have sudo privileges on your workstation. If that is not the case (e.g. if you are running on a corporate network where ``sudo`` usage is tracked), you can set the flag 'export THEME_CHECK_SUDO=false' in your ``~/.bashrc`` to disable the Powerline theme's ``sudo`` check. This will apply to all ``powerline*`` themes.
1212

1313
Provided Information
1414
--------------------
@@ -24,7 +24,7 @@ Provided Information
2424
* An indicator when connected by SSH
2525
* An indicator when ``sudo`` has the credentials cached (see the ``sudo`` manpage for more info about this)
2626
* An indicator when the current shell is inside the Vim editor
27-
* Battery charging status (depends on the battery plugin)
27+
* Battery charging status (depends on the battery library)
2828
* SCM Repository status (e.g. Git, SVN)
2929
* The current Kubernetes environment
3030
* The current Python environment (Virtualenv, venv, and Conda are supported) in use

docs/themes-list/powerline-multiline.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To get the length of the left and right segments right, a *padding* value is use
1919
In most cases, the default value (\ *2*\ ) works fine, but on some operating systems, this needs to be adjusted.
2020
One example is *macOS High Sierra*\ , where the default padding causes the right segment to extend to the next line.
2121
On macOS High Sierra, the padding value needs to be changed to *3* to make the theme look right.
22-
This can be done by setting the ``POWERLINE_PADDING`` variable before Bash-it is loaded, e.g. in your ``~/.bash_profile`` or ``~/.bashrc`` file:
22+
This can be done by setting the ``POWERLINE_PADDING`` variable before Bash-it is loaded, e.g. in your ``~/.bashrc`` file:
2323

2424
.. code-block:: bash
2525

docs/vcs_user.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Turn version control checking off to prevent slow directory navigation within la
1010
Controlling Flags
1111
^^^^^^^^^^^^^^^^^
1212

13-
Bash-it provides a flag (\ ``SCM_CHECK``\ ) within the ``~/.bash_profile`` file that turns off/on version control information checking and display within all themes.
13+
Bash-it provides a flag (\ ``SCM_CHECK``\ ) within the ``~/.bashrc`` file that turns off/on version control information checking and display within all themes.
1414
Version control checking is on by default unless explicitly turned off.
1515

1616
Set ``SCM_CHECK`` to 'false' to **turn off** version control checks for all themes:

0 commit comments

Comments
 (0)