Lucas
2 years ago
6 changed files with 301 additions and 2 deletions
@ -0,0 +1,5 @@ |
|||||
|
cache/ |
||||
|
log/ |
||||
|
|
||||
|
plugins/ |
||||
|
installed_plugins |
@ -1,3 +1,65 @@ |
|||||
# rock |
# ๐ธ Rock ๐ค |
||||
|
|
||||
|
A minimal zsh plugin manager. |
||||
|
|
||||
|
Inspired by: |
||||
|
zcomet - https://github.com/agkozak/zcomet |
||||
|
zap - https://github.com/zap-zsh/zap |
||||
|
|
||||
|
|
||||
|
## Install |
||||
|
|
||||
|
```sh |
||||
|
sh <(curl -s https://git.lucasf.dev/public/rock/raw/branch/master/install.sh) |
||||
|
``` |
||||
|
|
||||
|
## Basic plugins |
||||
|
|
||||
|
Add the following to your `.zshrc` |
||||
|
|
||||
|
```sh |
||||
|
# Basic Options for zsh configuration. |
||||
|
plug "https://git.lucasf.dev/public/zsh-basics.git" |
||||
|
|
||||
|
plug "zsh-users/zsh-autosuggestions" |
||||
|
plug "zsh-users/zsh-syntax-highlighting" |
||||
|
|
||||
|
# A simple prompt theme |
||||
|
plug "https://git.lucasf.dev/public/zsh-prompt.git" |
||||
|
``` |
||||
|
|
||||
|
## Commands |
||||
|
|
||||
|
- To update plugins or Rock itself: |
||||
|
|
||||
|
```sh |
||||
|
rock --update |
||||
|
``` |
||||
|
|
||||
|
- To cleanup plugins you are no longer using: |
||||
|
|
||||
|
```sh |
||||
|
rock --clean |
||||
|
``` |
||||
|
|
||||
|
- To uninstall Rock: |
||||
|
|
||||
|
```sh |
||||
|
rock --remove |
||||
|
``` |
||||
|
|
||||
|
## Notes |
||||
|
|
||||
|
By default the manager will try to source plugins that the file name is the same as the repository, with the following extensions: |
||||
|
|
||||
|
- `.plugin.zsh` |
||||
|
- `.zsh` |
||||
|
- `.zsh-theme` |
||||
|
|
||||
|
|
||||
|
To add some plugin that are named different from the repo name, you need to pass the file name as a parameter as in the example below: |
||||
|
|
||||
|
```sh |
||||
|
plug "spaceship-prompt/spaceship-prompt" spaceship.zsh |
||||
|
``` |
||||
|
|
||||
A minimal zsh plugin manager. |
|
@ -0,0 +1,8 @@ |
|||||
|
#compdef rock |
||||
|
|
||||
|
_arguments -C -s \ |
||||
|
"(-)"{-h,--help}"[Show help information]" \ |
||||
|
"(-)"{-v,--version}"[Show version information]" \ |
||||
|
"(-)"{-u,--update}"[Update plugins]" \ |
||||
|
"(-)"{-c,--clean}"[Remove unused plugins]" \ |
||||
|
"(-)"{-r,--remove}"[Uninstall rock]" \ |
@ -0,0 +1,8 @@ |
|||||
|
๐ธ rock [options] |
||||
|
|
||||
|
OPTIONS: |
||||
|
-h, --help help |
||||
|
-v, --version version |
||||
|
-u, --update update plugin(s) |
||||
|
-c, --clean clean plugin(s) |
||||
|
-r, --remove uninstall rock |
@ -0,0 +1,27 @@ |
|||||
|
#!/bin/sh |
||||
|
|
||||
|
main() { |
||||
|
local ROCKDIR="$HOME/.local/share/rock" |
||||
|
local ZSHRC="$HOME/.zshrc" |
||||
|
local CMD='[[ -f "$HOME/.local/share/rock/rock.zsh" ]] && source "$HOME/.local/share/rock/rock.zsh"' |
||||
|
|
||||
|
git clone https://git.lucasf.dev/public/rock "$ROCKDIR" > /dev/null 2>&1 |
||||
|
if [[ ! -d "$ROCKDIR/plugins" ]]; then |
||||
|
mkdir -p "$ROCKDIR/plugins" |
||||
|
fi |
||||
|
if [[ -n "$ZDOTDIR" ]] && [[ -f "$ZDOTDIR/.zshrc" ]]; then |
||||
|
ZSHRC="$ZDOTDIR/.zshrc" |
||||
|
fi |
||||
|
if [[ ! -f $ZSHRC || $(cat $ZSHRC | wc -l) = 0 ]];then |
||||
|
echo $CMD > $ZSHRC |
||||
|
else |
||||
|
if ! grep -q '[[ -f "$HOME/.local/share/rock/rock.zsh" ]] && source "$HOME/.local/share/rock/rock.zsh"' $ZSHRC; then |
||||
|
sed -i '1 i[[ -f "$HOME/.local/share/rock/rock.zsh" ]] && source "$HOME/.local/share/rock/rock.zsh"' $ZSHRC |
||||
|
fi |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
main |
||||
|
if [[ $? -eq 0 ]];then echo "๐ธ You Rock Yeah!! ๐ค"; fi |
||||
|
|
||||
|
# vim: ft=zsh:ts=4:sts=4:sw=4 |
@ -0,0 +1,189 @@ |
|||||
|
#!/bin/sh |
||||
|
# Rock Zsh Plugin Manager - inspired by zcomet & zap |
||||
|
# shellcheck disable=SC1090 |
||||
|
|
||||
|
export ROCK_DIR="$HOME/.local/share/rock" |
||||
|
export ROCK_PLUGIN_DIR="$ROCK_DIR/plugins" |
||||
|
export ROCK_ACTIVE_PLUGINS="$ROCK_DIR/installed_plugins" |
||||
|
export ROCK_ZSHRC="$ZDOTDIR/.zshrc" |
||||
|
export ZSH_CACHE_DIR="$ROCK_DIR/cache/" |
||||
|
plugin_name="" |
||||
|
|
||||
|
if [ -z "$ZDOTDIR" ]; then |
||||
|
export ROCK_ZSHRC="$HOME/.zshrc" # ~/.zshrc |
||||
|
fi |
||||
|
|
||||
|
fpath=("$ROCK_DIR/completion" $fpath) |
||||
|
autoload -Uz add-zsh-hook \ |
||||
|
_rock_{help,version,update,clean,remove} |
||||
|
|
||||
|
rm -rf "$ROCK_ACTIVE_PLUGINS" |
||||
|
|
||||
|
_try_source() { |
||||
|
[[ -f "$1" ]] && source "$1" |
||||
|
} |
||||
|
|
||||
|
_get_plugin_name() { |
||||
|
plugin_name=$(echo "$1" | awk -F / '{print $NF}') |
||||
|
plugin_name="${plugin_name/.git/}" |
||||
|
} |
||||
|
|
||||
|
_try_pull() { |
||||
|
echo "โช $1" |
||||
|
git pull > /dev/null 2>&1 |
||||
|
if [ $? -ne 0 ]; then echo "Failed to update $1" && return 1; fi |
||||
|
echo -e "\e[1A\e[K๐ถ $1" |
||||
|
} |
||||
|
|
||||
|
_rock_help() { |
||||
|
cat "$ROCK_DIR/help" |
||||
|
} |
||||
|
|
||||
|
_rock_version() { |
||||
|
echo "๐ธ Rock Version $(cat "$ROCK_DIR/.git/packed-refs" | grep tags | tail -1 | awk -F / '{print $NF}')" |
||||
|
} |
||||
|
|
||||
|
_rock_update() { |
||||
|
local plugins="" |
||||
|
if [[ -f "$ROCK_ACTIVE_PLUGINS" ]];then |
||||
|
plugins=$(cat "$ROCK_ACTIVE_PLUGINS" | awk 'BEGIN { FS = "\n" } { print " " int((NR)) echo " โช " $1 }') |
||||
|
fi |
||||
|
echo "๐ผ Please select an option to update \n" |
||||
|
echo -e " 0 ๐ธ Rock" |
||||
|
echo "$plugins \n" |
||||
|
echo -n "๐ผ Plugin Number(s) | (a) All Plugins | (0) ๐ธ update Rock: " |
||||
|
read plugin |
||||
|
pwd=$(pwd) |
||||
|
echo "" |
||||
|
if [[ $plugin == "a" ]]; then |
||||
|
cd "$ROCK_PLUGIN_DIR" |
||||
|
for plug in *; do |
||||
|
cd $plug |
||||
|
_try_pull $plug |
||||
|
cd "$ROCK_PLUGIN_DIR" |
||||
|
done |
||||
|
cd $pwd > /dev/null 2>&1 |
||||
|
elif [[ $plugin == "0" ]]; then |
||||
|
cd "$ROCK_DIR" |
||||
|
_try_pull 'rock' |
||||
|
cd $pwd |
||||
|
else |
||||
|
selected_number=($(echo $plugin | awk -F '[[:space:]]' '{print $0}')) |
||||
|
sorted=($(printf '%s\n' "${selected_number[@]}"|sort -u)) |
||||
|
for item in $sorted;do |
||||
|
for plug in $plugins; do |
||||
|
selected=$(echo $plug | grep -E "^ ${item##*( )}" | awk -F / '{print $NF}') |
||||
|
selected="${selected/.git/}" |
||||
|
if [[ -n $selected ]]; then |
||||
|
if [[ -d "$ROCK_PLUGIN_DIR/$selected" ]];then |
||||
|
cd "$ROCK_PLUGIN_DIR/$selected" |
||||
|
_try_pull $selected |
||||
|
cd - > /dev/null 2>&1 |
||||
|
fi |
||||
|
else |
||||
|
echo "๐ฃ ${item##*( )} is not a valid option!" |
||||
|
fi |
||||
|
done |
||||
|
done |
||||
|
fi |
||||
|
if [[ $ROCK_CLEAN_ON_UPDATE == true ]]; then |
||||
|
_rock_clean |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_rock_clean() { |
||||
|
unused_plugins=() |
||||
|
for i in "$ROCK_PLUGIN_DIR"/*; do |
||||
|
local plugin_name=$(basename "$i") |
||||
|
if ! grep -q "$plugin_name" "$ROCK_ACTIVE_PLUGINS"; then |
||||
|
unused_plugins+=("$plugin_name") |
||||
|
fi |
||||
|
done |
||||
|
if [ ${#unused_plugins[@]} -eq 0 ]; then |
||||
|
echo "๐ฃ Nothing to clean" |
||||
|
else |
||||
|
for p in ${unused_plugins[@]}; do |
||||
|
echo -n "Remove: $p? (n/y): " |
||||
|
read answer |
||||
|
if [[ $answer == "y" || $answer == "Y" ]]; then |
||||
|
rm -rf "$ROCK_PLUGIN_DIR/$p" |
||||
|
echo "removed: $p" |
||||
|
fi |
||||
|
done |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_rock_remove() { |
||||
|
echo -n "๐ Removing Rock, are you sure? (n/y):" |
||||
|
read answer |
||||
|
if [[ $answer == "y" || $answer == "Y" ]];then |
||||
|
cd "$HOME" |
||||
|
rm -rf "$ROCK_DIR" |
||||
|
if [[ -f $ROCK_ZSHRC ]];then |
||||
|
sed -i '/source "$HOME\/.local\/share\/rock\/rock.zsh"/d' $ROCK_ZSHRC |
||||
|
sed -i '/^plug /d' $ROCK_ZSHRC |
||||
|
source $ROCK_ZSHRC |
||||
|
fi |
||||
|
echo "๐ Bye Bye" |
||||
|
else |
||||
|
echo "Great choice! ๐ต๐ง๐ญ ๐ถ" |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
plug() { |
||||
|
local plugin="$1" |
||||
|
if [[ -f "$plugin" ]];then |
||||
|
_try_source $plugin |
||||
|
else |
||||
|
local full_plugin_name="$1" |
||||
|
_get_plugin_name $plugin |
||||
|
local plugin_nick=$(echo $* | awk -F "[[:space:]]" '/.zsh$/{print $NF}') |
||||
|
local plugin_dir="$ROCK_PLUGIN_DIR/$plugin_name" |
||||
|
if [[ ! -d "$plugin_dir" ]];then |
||||
|
echo "โช $plugin_name" |
||||
|
git clone $plugin --depth 1 "$plugin_dir" > /dev/null 2>&1 |
||||
|
if [ $? -ne 0 ]; then |
||||
|
git clone "https://github.com/$plugin.git" --depth 1 "$plugin_dir" > /dev/null 2>&1 |
||||
|
if [ $? -ne 0 ]; then echo "Failed to clone $plugin_name" && return 1; fi |
||||
|
fi |
||||
|
if [ -n "$git_ref" ]; then |
||||
|
git -C "$plugin_dir" checkout "$git_ref" > /dev/null 2>&1 |
||||
|
if [ $? -ne 0 ]; then echo "Failed to checkout $git_ref" && return 1; fi |
||||
|
fi |
||||
|
echo -e "\e[1A\e[K๐ถ $plugin_name" |
||||
|
fi |
||||
|
_try_source "$plugin_dir/$plugin_name.plugin.zsh" |
||||
|
_try_source "$plugin_dir/$plugin_name.zsh" |
||||
|
_try_source "$plugin_dir/$plugin_name.zsh-theme" |
||||
|
if [[ -n "$plugin_nick" ]];then _try_source "$plugin_dir/$plugin_nick"; fi |
||||
|
fi |
||||
|
if [[ -n $full_plugin_name ]]; then |
||||
|
echo "$full_plugin_name" >> "$ROCK_DIR/installed_plugins" |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
typeset -A opts |
||||
|
opts=( |
||||
|
-h "_rock_help" |
||||
|
--help "_rock_help" |
||||
|
-u "_rock_update" |
||||
|
--update "_rock_update" |
||||
|
-c "_rock_clean" |
||||
|
--clean "_rock_clean" |
||||
|
-v "_rock_version" |
||||
|
--version "_rock_version" |
||||
|
-r "_rock_remove" |
||||
|
--remove "_rock_remove" |
||||
|
) |
||||
|
|
||||
|
rock() { |
||||
|
emulate -L zsh |
||||
|
if [[ -z "$opts[$1]" ]]; then |
||||
|
_rock_help |
||||
|
return 1 |
||||
|
fi |
||||
|
opt="${opts[$1]}" |
||||
|
$opt |
||||
|
} |
||||
|
|
||||
|
# vim: ft=bash sw=4 ts=4 et |
Loadingโฆ
Reference in new issue