Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto formatting and CI! #40

Merged
merged 6 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[*.*sh]
shell_variant = bash
indent_style = space
indent_size = 4
space_redirects = true
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.0
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.5.1-1
hooks:
- id: shfmt # requires Go to build
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,29 @@ Will only work with plugins that are named conventionally, this means that the p
- `.zsh`
- `.zsh-theme`

For example: [vim](https://github.com/zap-zsh/vim)
For example: [vim](https://github.com/zap-zsh/vim)

## Development & CI

Auto formatted code with [`shfmt`](https://github.com/mvdan/sh#shfmt) is required for a pull request to be merged.

Format code:

```bash
shfmt -l -w .
```

### pre-commit

To add a formatting check on each commit [pre-commit](https://pre-commit.com/#intro) can be used.
shfmt via Go is required for pre-commit to work.

Install `pre-commit`:

```bash
pip install pre-commit
pre-commit install
```

<!----------------------------------------------------------------------------->

Expand Down
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ main() {

main
echo " Zapped"

# vim: ft=bash ts=4 et
111 changes: 56 additions & 55 deletions zap.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ _try_source() {
}

plug() {
plugin="$1"
plugin="$1"
if [ -f "$plugin" ]; then
source "$plugin"
else
local full_plugin_name="$1"
local initialize_completion="$2"
local plugin_name=$(echo "$full_plugin_name" | cut -d "/" -f 2)
local plugin_dir="$ZAP_PLUGIN_DIR/$plugin_name"
if [ ! -d "$plugin_dir" ]; then
echo "🔌$plugin_name"
git clone "https://github.com/${full_plugin_name}.git" "$plugin_dir" > /dev/null 2>&1
if [[ ! -z $2 ]]; then # check if the second arg of plug exist
cd $plugin_dir && git checkout "$2" > /dev/null 2>&1 && cd # checkout the desidered commit
fi
if [ $? -ne 0 ]; then
echo "Failed to install $plugin_name"
exit 1
source "$plugin"
else
local full_plugin_name="$1"
local initialize_completion="$2"
local plugin_name=$(echo "$full_plugin_name" | cut -d "/" -f 2)
local plugin_dir="$ZAP_PLUGIN_DIR/$plugin_name"
if [ ! -d "$plugin_dir" ]; then
echo "🔌$plugin_name"
git clone "https://github.com/${full_plugin_name}.git" "$plugin_dir" > /dev/null 2>&1
if [[ -n $2 ]]; then # check if the second arg of plug exist
cd $plugin_dir && git checkout "$2" > /dev/null 2>&1 && cd # checkout the desidered commit
fi
if [ $? -ne 0 ]; then
echo "Failed to install $plugin_name"
exit 1
fi
echo -e "\e[1A\e[K⚡$plugin_name"
fi
echo -e "\e[1A\e[K⚡$plugin_name"
_try_source "$plugin_dir/$plugin_name.plugin.zsh"
_try_source "$plugin_dir/$plugin_name.zsh"
_try_source "$plugin_dir/$plugin_name.zsh-theme"
fi
_try_source "$plugin_dir/$plugin_name.plugin.zsh"
_try_source "$plugin_dir/$plugin_name.zsh"
_try_source "$plugin_dir/$plugin_name.zsh-theme"
fi
}

_pull () {
_pull() {
echo "🔌$1"
git pull > /dev/null 1>&1
if [ $? -ne 0 ]; then
Expand All @@ -45,19 +45,19 @@ _pull () {
echo -e "\e[1A\e[K⚡$1"
}

update () {
update() {
ls -1 "$ZAP_PLUGIN_DIR"
echo ""
echo "Plugin Name / (a) for All Plugins / (self) for Zap Itself: "
read plugin;
read plugin
pwd=$(pwd)
echo ""
if [[ $plugin == "a" ]]; then
cd "$ZAP_PLUGIN_DIR"
for plug in *; do
cd $plug
_pull $plug
cd ..;
cd ..
done
cd $pwd
elif [[ $plugin == "self" ]]; then
Expand All @@ -71,62 +71,63 @@ update () {
fi
}

delete () {
delete() {
ls -1 "$ZAP_PLUGIN_DIR"
echo -n "Plugin Name: ";
read plugin;
echo -n "Plugin Name: "
read plugin
cd "$ZAP_PLUGIN_DIR" && echo "Deleting $plugin ..." && rm -rf $plugin > /dev/null 2>&1 && cd - > /dev/null 2>&1 && echo "Deleted $plugin " || echo "Failed to delete : $plugin"
}

pause() {
ls -1 "$ZAP_PLUGIN_DIR"
echo ""
echo -n "Plugin Name or (a) to Update All: ";
read plugin;
echo -n "Plugin Name or (a) to Update All: "
read plugin
if [[ $plugin == "a" ]]; then
sed -i '/^plug/s/^/#/g' ~/.zshrc
sed -i '/^plug/s/^/#/g' ~/.zshrc
else
sed -i "/\/$plugin/s/^/#/g" ~/.zshrc
sed -i "/\/$plugin/s/^/#/g" ~/.zshrc
fi
}

unpause() {
ls -1 "$ZAP_PLUGIN_DIR"
echo ""
echo -n "Plugin Name or (a) to Update All: ";
read plugin;
echo -n "Plugin Name or (a) to Update All: "
read plugin
if [[ $plugin == "a" ]]; then
sed -i '/^#plug/s/^#//g' ~/.zshrc
sed -i '/^#plug/s/^#//g' ~/.zshrc
else
sed -i "/\/$plugin/s/^#//g" ~/.zshrc
sed -i "/\/$plugin/s/^#//g" ~/.zshrc
fi
}

Help () {
cat "$ZAP_DIR/doc.txt"
Help() {
cat "$ZAP_DIR/doc.txt"
}

Version () {
ref=$ZAP_DIR/.git/packed-refs
tag=$(awk 'BEGIN { FS = "[ /]" } { print $3, $4 }' $ref | grep tags);
ver=$(echo $tag | cut -d " " -f 2)
echo "⚡Zap Version v$ver"
Version() {
ref=$ZAP_DIR/.git/packed-refs
tag=$(awk 'BEGIN { FS = "[ /]" } { print $3, $4 }' $ref | grep tags)
ver=$(echo $tag | cut -d " " -f 2)
echo "⚡Zap Version v$ver"
}

zap() {
local command="$1"
if [[ "$command" == "-v" ]] || [[ "$command" == "--version" ]]; then
Version;
return;
if [[ $command == "-v" ]] || [[ $command == "--version" ]]; then
Version
return
else
if [[ "$command" == "-h" ]] || [[ "$command" == "--help" ]]; then
Help;
return;
else
$command;
return;
fi
echo "$command: command not found"
fi
if [[ $command == "-h" ]] || [[ $command == "--help" ]]; then
Help
return
else
$command
return
fi
echo "$command: command not found"
fi
}

# vim: ft=bash ts=4 et