chezmoi init

This commit is contained in:
Cy Pokhrel 2024-10-22 11:11:45 -04:00
commit 530d6d7195
No known key found for this signature in database
GPG key ID: 1200FBE36C2ADE2E
1176 changed files with 111325 additions and 0 deletions

View file

@ -0,0 +1,74 @@
# Bundler
This plugin adds completion for basic bundler commands, as well as aliases and helper functions for
an easier experience with bundler.
To use it, add `bundler` to the plugins array in your zshrc file:
```zsh
plugins=(... bundler)
```
## Aliases
| Alias | Command | Description |
|--------|--------------------------------------|------------------------------------------------------------------------------------------|
| `ba` | `bundle add` | Add gem to the Gemfile and run bundle install |
| `bck` | `bundle check` | Verifies if dependencies are satisfied by installed gems |
| `bcn` | `bundle clean` | Cleans up unused gems in your bundler directory |
| `be` | `bundle exec` | Execute a command in the context of the bundle |
| `bi` | `bundle install --jobs=<core_count>` | Install the dependencies specified in your Gemfile (using all cores in bundler >= 1.4.0) |
| `bl` | `bundle list` | List all the gems in the bundle |
| `bo` | `bundle open` | Opens the source directory for a gem in your bundle |
| `bout` | `bundle outdated` | List installed gems with newer versions available |
| `bp` | `bundle package` | Package your needed .gem files into your application |
| `bu` | `bundle update` | Update your gems to the latest available versions |
## Gem wrapper
The plugin adds a wrapper for common gems, which:
- Looks for a binstub under `./bin/` and executes it if present.
- Calls `bundle exec <gem>` otherwise.
Common gems wrapped by default (by name of the executable):
`annotate`, `cap`, `capify`, `cucumber`, `foodcritic`, `guard`, `hanami`, `irb`, `jekyll`, `kitchen`, `knife`, `middleman`, `nanoc`, `pry`, `puma`, `rackup`, `rainbows`, `rake`, `rspec`, `rubocop`, `shotgun`, `sidekiq`, `spec`, `spork`, `spring`, `strainer`, `tailor`, `taps`, `thin`, `thor`, `unicorn` and `unicorn_rails`.
### Settings
You can add or remove gems from the list of wrapped commands.
Please **use the exact name of the executable** and not the gem name.
#### Include gems to be wrapped (`BUNDLED_COMMANDS`)
Add this before the plugin list in your `.zshrc`:
```sh
BUNDLED_COMMANDS=(rubocop)
plugins=(... bundler ...)
```
This will add the wrapper for the `rubocop` gem (i.e. the executable).
#### Exclude gems from being wrapped (`UNBUNDLED_COMMANDS`)
Add this before the plugin list in your `.zshrc`:
```sh
UNBUNDLED_COMMANDS=(foreman spin)
plugins=(... bundler ...)
```
This will exclude the `foreman` and `spin` gems (i.e. their executable) from being wrapped.
### Excluded gems
These gems should not be called with `bundle exec`. Please see [issue #2923](https://github.com/ohmyzsh/ohmyzsh/pull/2923) on GitHub for clarification:
- `berks`
- `foreman`
- `mailcatcher`
- `rails`
- `ruby`
- `spin`

View file

@ -0,0 +1,105 @@
#compdef bundle bundler
local curcontext="$curcontext" state line _gems _opts ret=1
_arguments -C -A "-v" -A "--version" \
'(- 1 *)'{-v,--version}'[display version information]' \
'1: :->cmds' \
'*:: :->args' && ret=0
case $state in
cmds)
_values "bundle command" \
"install[Install the gems specified by the Gemfile or Gemfile.lock]" \
"update[Update dependencies to their latest versions]" \
"package[Package the .gem files required by your application]" \
"exec[Execute a script in the context of the current bundle]" \
"config[Specify and read configuration options for bundler]" \
"check[Determine whether the requirements for your application are installed]" \
"list[Show all of the gems in the current bundle]" \
"show[Show the source location of a particular gem in the bundle]" \
"info[Show details of a particular gem in the bundle]" \
"outdated[Show all of the outdated gems in the current bundle]" \
"console[Start an IRB session in the context of the current bundle]" \
"open[Open an installed gem in the editor]" \
"viz[Generate a visual representation of your dependencies]" \
"init[Generate a simple Gemfile, placed in the current directory]" \
"gem[Create a simple gem, suitable for development with bundler]" \
"platform[Displays platform compatibility information]" \
"clean[Cleans up unused gems in your bundler directory]" \
"help[Describe available tasks or one specific task]"
ret=0
;;
args)
case $line[1] in
help)
_values 'commands' \
'install' \
'update' \
'package' \
'exec' \
'config' \
'check' \
'list' \
'show' \
'outdated' \
'console' \
'open' \
'viz' \
'init' \
'gem' \
'platform' \
'help' && ret=0
;;
install)
_arguments \
'(--no-color)--no-color[disable colorization in output]' \
'(--local)--local[do not attempt to connect to rubygems.org]' \
'(--quiet)--quiet[only output warnings and errors]' \
'(--gemfile)--gemfile=-[use the specified gemfile instead of Gemfile]:gemfile' \
'(--system)--system[install to the system location]' \
'(--deployment)--deployment[install using defaults tuned for deployment environments]' \
'(--frozen)--frozen[do not allow the Gemfile.lock to be updated after this install]' \
'(--path)--path=-[specify a different path than the system default]:path:_files' \
'(--binstubs)--binstubs=-[generate bin stubs for bundled gems to ./bin]:directory:_files' \
'(--without)--without=-[exclude gems that are part of the specified named group]:groups'
ret=0
;;
exec)
_normal && ret=0
;;
clean)
_arguments \
'(--force)--force[forces clean even if --path is not set]' \
'(--dry-run)--dry-run[only print out changes, do not actually clean gems]' \
'(--no-color)--no-color[Disable colorization in output]' \
'(--verbose)--verbose[Enable verbose output mode]'
ret=0
;;
outdated)
_arguments \
'(--pre)--pre[Check for newer pre-release gems]' \
'(--source)--source[Check against a specific source]' \
'(--local)--local[Do not attempt to fetch gems remotely and use the gem cache instead]' \
'(--no-color)--no-color[Disable colorization in output]' \
'(--verbose)--verbose[Enable verbose output mode]'
ret=0
;;
(open|show|info)
_gems=( $(bundle show 2> /dev/null | sed -e '/^ \*/!d; s/^ \* \([^ ]*\) .*/\1/') )
if [[ $_gems != "" ]]; then
_values 'gems' $_gems && ret=0
fi
;;
*)
_opts=( $(bundle help $line[1] | sed -e '/^ \[-/!d; s/^ \[\(-[^=]*\)=.*/\1/') )
_opts+=( $(bundle help $line[1] | sed -e '/^ -/!d; s/^ \(-.\), \[\(-[^=]*\)=.*/\1 \2/') )
if [[ $_opts != "" ]]; then
_values 'options' $_opts && ret=0
fi
;;
esac
;;
esac
return ret

View file

@ -0,0 +1,127 @@
## Aliases
alias ba="bundle add"
alias bck="bundle check"
alias bcn="bundle clean"
alias be="bundle exec"
alias bi="bundle_install"
alias bl="bundle list"
alias bo="bundle open"
alias bout="bundle outdated"
alias bp="bundle package"
alias bu="bundle update"
## Functions
bundle_install() {
# Bail out if bundler is not installed
if (( ! $+commands[bundle] )); then
echo "Bundler is not installed"
return 1
fi
# Bail out if not in a bundled project
if ! _within-bundled-project; then
echo "Can't 'bundle install' outside a bundled project"
return 1
fi
# Check the bundler version is at least 1.4.0
autoload -Uz is-at-least
local bundler_version=$(bundle version | cut -d' ' -f3)
if ! is-at-least 1.4.0 "$bundler_version"; then
bundle install "$@"
return $?
fi
# If bundler is at least 1.4.0, use all the CPU cores to bundle install
if [[ "$OSTYPE" = (darwin|freebsd)* ]]; then
local cores_num="$(sysctl -n hw.ncpu)"
else
local cores_num="$(nproc)"
fi
BUNDLE_JOBS="$cores_num" bundle install "$@"
}
## Gem wrapper
bundled_commands=(
annotate
cap
capify
cucumber
foodcritic
guard
hanami
irb
jekyll
kitchen
knife
middleman
nanoc
pry
puma
rackup
rainbows
rake
rspec
rubocop
shotgun
sidekiq
spec
spork
spring
strainer
tailor
taps
thin
thor
unicorn
unicorn_rails
)
# Remove $UNBUNDLED_COMMANDS from the bundled_commands list
bundled_commands=(${bundled_commands:|UNBUNDLED_COMMANDS})
unset UNBUNDLED_COMMANDS
# Add $BUNDLED_COMMANDS to the bundled_commands list
bundled_commands+=($BUNDLED_COMMANDS)
unset BUNDLED_COMMANDS
# Check if in the root or a subdirectory of a bundled project
_within-bundled-project() {
local check_dir="$PWD"
while [[ "$check_dir" != "/" ]]; do
if [[ -f "$check_dir/Gemfile" || -f "$check_dir/gems.rb" ]]; then
return 0
fi
check_dir="${check_dir:h}"
done
return 1
}
_run-with-bundler() {
if (( ! $+commands[bundle] )) || ! _within-bundled-project; then
"$@"
return $?
fi
if [[ -f "./bin/${1}" ]]; then
./bin/${^^@}
else
bundle exec "$@"
fi
}
for cmd in $bundled_commands; do
# Create wrappers for bundled and unbundled execution
eval "function unbundled_$cmd () { \"$cmd\" \"\$@\"; }"
eval "function bundled_$cmd () { _run-with-bundler \"$cmd\" \"\$@\"; }"
alias "$cmd"="bundled_$cmd"
# Bind completion function to wrapped gem if available
if (( $+functions[_$cmd] )); then
compdef "_$cmd" "bundled_$cmd"="$cmd"
fi
done
unset cmd bundled_commands