Skip to content

Instantly share code, notes, and snippets.

@walbon
Last active October 27, 2015 13:34
Show Gist options
  • Save walbon/9f1facb1019cfc0c9635 to your computer and use it in GitHub Desktop.
Save walbon/9f1facb1019cfc0c9635 to your computer and use it in GitHub Desktop.
#!/bin/bash
#alias .CHOOSE='if [[ $FILES ]] ; then ~/.choosing.sh ${FILES} | while read line; do for item in $line; do echo $item; done | xargs ${COM} ; done ; fi; FILES=""; COM=""'
# Usage :
# FILES=$(ls *.txt); COM="egrep -i walbon"; .CHOOSE
#
pkglist=""
pkglist2=""
n=1
echo $*
for pkg in $*
do
pkglist="$pkglist $n $pkg off"
pkglist2="$pkglist2;-$n;$pkg|"
n=$[n+1]
done
choices=`/usr/bin/dialog --stdout --checklist 'Choose item:' 80 40 $n $pkglist`
stdouted=""
if [ $? -eq 0 ]
then
for choice in $choices
do
for item in $(echo $pkglist2 | sed -e "s/|/ /g")
do
stdouted="$stdouted `echo $item | egrep ";-$choice;" | cut -d';' -f3-`"
done
done
else
exit 1
fi
echo $stdouted
export stdouted="$stdouted"
#$ ./.choosing.sh onca macaco baleia girafa veado |while read line; do for item in $line; do echo $item; done | xargs ls ; done
#COM="ls -hs";FILES="$(ls)";./.choosing.sh ${FILES} |while read line; do for item in $line; do echo $item; done | xargs ${COM} ; done
#alias .CHOOSING="read FILES; read COM; if [[ \$FILES ]] ; then ~/.choosing.sh \${FILES} | while read line; do for item in \$line; do echo \$item; done | xargs \${COM} ; done ; fi;"
#alias .CHOOSING="read FILES; read COM; if [[ \$FILES ]] ; then ~/.choosing.sh \${FILES} | while read line; do for item in \$line; do echo \$item; done | xargs \${COM} ; done ; fi;"
#alias .CHOOSE='if [[ $FILES ]] ; then ~/.choosing.sh ${FILES} | while read line; do for item in $line; do echo $item; done | xargs ${COM} ; done ; else echo; echo "CHOSE usage: You need define the environment variables, FILES and COM."; echo " - FILES: Itens to be choose."; echo " - COM: The command that will execute." ; fi; FILES=""; COM=""'
@walbon
Copy link
Author

walbon commented Oct 27, 2015

alias .CHOOSING="read FILES; read COM; if [[ $FILES ]] ; then ~/.choosing.sh ${FILES} | while read line; do for item in $line; do echo $item; done | xargs ${COM} ; done ; fi;"
alias .CHOOSE='if [[ $FILES ]] ; then ~/.choosing.sh ${FILES} | while read line; do for item in $line; do echo $item; done | xargs ${COM} ; done ; else echo; echo "CHOSE usage: You need define the environment variables, FILES and COM."; echo " - FILES: Itens to be choose."; echo " - COM: The command that will execute." ; fi; FILES=""; COM=""'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment