xbar-plugins icon indicating copy to clipboard operation
xbar-plugins copied to clipboard

Plugin to move plugins from active/nonactive folders

Open JaredVogt opened this issue 9 years ago • 3 comments

Here is rudimentary plugin to manage plugins... except I can't figure out syntax around | bash= in the plugin API. My shell-foo is rough, so who knows what I am doing wrong.

#!/bin/bash

echo 'Plugins'
echo '---'
dirname=${0%/*}  # use this to get the directory
echo "Root directory: $dirname | color=white refresh=true"
echo "Inactive directory: ${dirname}/inactive | color=white"
echo "=========================== "

filesActive=($(ls $dirname))
filesInactive=($(ls "${dirname}/inactive"))

echo "Click on item in list to move to inactive | color=blue"

for var in "${filesActive[@]}"
do
  # this kinda works, but 1) opens terminal and 2) doesn't refresh the plug with new info
  # when I add in refresh=true terminal=false, no go...
  echo "${var} | color=red bash='mv "${dirname}/${var}" "${dirname}/inactive/${var}"'"
done

echo "Click on item in list to move to active | color=blue"

for var in "${filesInactive[@]}"
do
  echo "${var} | color=red bash='mv "${dirname}/inactive/${var}" "${dirname}/${var}"'" 
done

Getting this line echo "${var} | color=red bash='mv "${dirname}/${var}" "${dirname}/inactive/${var}"'" correct is the key. I tried every combination of " and ' and order of refresh=true and terminal=false, to no avail. Anyone see how to make it work?

JaredVogt avatar Jan 27 '16 06:01 JaredVogt

Hey @JaredVogt, cool idea!

The bash param takes one argument, and then you have param1..param5 to pass arguments to the command. Also - you might want to use ln to symbolically link the files, instead of mv.

I'd probably rewrite what you have as this: (this also follows the directory structure of this plugins repo)

#!/bin/bash
PLUGIN_DIR="$(dirname "$0")/../"
ACTIVE_PLUGIN_DIR=$(dirname "$0")
ACTIVE_PLUGIN_COUNT=$(($(ls -l "$ACTIVE_PLUGIN_DIR" | wc -l) - 1))

echo "🔌$ACTIVE_PLUGIN_COUNT"
echo "---"

echo "Enabled Plugins (click to remove)"
ACTIVE_PLUGINS=($(ls $ACTIVE_PLUGIN_DIR))
INACTIVE_PLUGINS=($(find $PLUGIN_DIR -not -path "$ACTIVE_PLUGIN_DIR" -not -path "*.git*" -type f))
for PLUGIN in "${ACTIVE_PLUGINS[@]}"
do
  echo "${PLUGIN} | color=green refresh=true terminal=false bash=$(which rm) param1='$ACTIVE_PLUGIN_DIR/$PLUGIN'"
done

echo "---"

echo "Disabled Plugins (click to add)"
for PLUGIN in "${INACTIVE_PLUGINS[@]}"
do
  PLUGIN_NAME=$(basename $PLUGIN)
  echo "${PLUGIN_NAME} | color=red refresh=true terminal=false bash=$(which ln) param1=-sf param2='$PLUGIN' param3='$ACTIVE_PLUGIN_DIR/$PLUGIN_NAME'"
done

Hopefully this gives you some inspiration, and I look forward to your PR!

keithamus avatar Jan 27 '16 10:01 keithamus

What is the progress on this?

iosdeveloper avatar Feb 18 '16 10:02 iosdeveloper

Great idea!

CBC1L avatar Apr 29 '17 13:04 CBC1L