From cdd5045184e8dfb66bbdaa37ce7e13c6bccf71a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2EFernando=20S=C3=A1nchez?= Date: Sun, 10 Jul 2011 04:39:44 +0200 Subject: [PATCH] One-instance and bashrc scripts. Plus a modified script to download songs from goear --- bashrc | 125 ++++++++++++++++++++++++++++++++++++++++++++ gnome-terminal | 2 + goear.sh | 70 +++++++++++++++++++++++++ one-instance | 25 +++++++++ one-instance (copy) | 27 ++++++++++ one-terminator.sh | 10 ++++ one-window | 25 +++++++++ start-eclipse.sh | 17 ++++++ terminator | 2 + 9 files changed, 303 insertions(+) create mode 100644 bashrc create mode 100755 gnome-terminal create mode 100755 goear.sh create mode 100755 one-instance create mode 100755 one-instance (copy) create mode 100755 one-terminator.sh create mode 100755 one-window create mode 100644 start-eclipse.sh create mode 100755 terminator diff --git a/bashrc b/bashrc new file mode 100644 index 0000000..ed83f3d --- /dev/null +++ b/bashrc @@ -0,0 +1,125 @@ +# ~/.bashrc: executed by bash(1) for non-login shells. +# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) +# for examples + +# If not running interactively, don't do anything +[ -z "$PS1" ] && return + +# don't put duplicate lines in the history. See bash(1) for more options +# ... or force ignoredups and ignorespace +HISTCONTROL=ignoredups:ignorespace + +# append to the history file, don't overwrite it +shopt -s histappend + +# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) +HISTSIZE=1000 +HISTFILESIZE=2000 + +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize + +# make less more friendly for non-text input files, see lesspipe(1) +[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" + +# set variable identifying the chroot you work in (used in the prompt below) +if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then + debian_chroot=$(cat /etc/debian_chroot) +fi + +# set a fancy prompt (non-color, unless we know we "want" color) +case "$TERM" in + xterm-color) color_prompt=yes;; + xterm) color_prompt=yes;; +esac + +# uncomment for a colored prompt, if the terminal has the capability; turned +# off by default to not distract the user: the focus in a terminal window +# should be on the output of commands, not on the prompt +force_color_prompt=yes + +if [ -n "$force_color_prompt" ]; then + if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then + # We have color support; assume it's compliant with Ecma-48 + # (ISO/IEC-6429). (Lack of such support is extremely rare, and such + # a case would tend to support setf rather than setaf.) + color_prompt=yes + else + color_prompt= + fi +fi + +if [ "$color_prompt" = yes ]; then + export PROMPT_COMMAND='PS1="\\[\033[1;\`if [[ \$? = "0" ]]; then echo "32m\\]"; else echo "31m\\]"; fi\`[\!]\\[\033[0m\]\u@\h \W: "' +else + PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' +fi + +unset color_prompt force_color_prompt + +# If this is an xterm set the title to user@host:dir +case "$TERM" in +xterm*|rxvt*) + PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" + ;; +*) + ;; +esac + +# enable color support of ls and also add handy aliases +if [ -x /usr/bin/dircolors ]; then + test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" + alias ls='ls --color=auto' + #alias dir='dir --color=auto' + #alias vdir='vdir --color=auto' + + alias grep='grep --color=auto' + alias fgrep='fgrep --color=auto' + alias egrep='egrep --color=auto' +fi + +# some more ls aliases +alias ll='ls -alhF' +alias la='ls -A' +alias l='ls -CF' + +# Add an "alert" alias for long running commands. Use like so: +# sleep 10; alert +alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' + +# Alias definitions. +# You may want to put all your additions into a separate file like +# ~/.bash_aliases, instead of adding them here directly. +# See /usr/share/doc/bash-doc/examples in the bash-doc package. + +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi + +# enable programmable completion features (you don't need to enable +# this, if it's already enabled in /etc/bash.bashrc and /etc/profile +# sources /etc/bash.bashrc). +if [ -f /etc/bash_completion ] && ! shopt -oq posix; then + . /etc/bash_completion +fi +export CDPATH=~:/media/Datos:/home/balkian + +if [ "$TERM" = "linux" ]; then + alias logout="clear && logout && exit" +else + alias logout="exit 0" +fi +export PYTHONSTARTUP=/home/$USER/.pythonrc +export PATH=$PATH:/var/lib/gems/1.8/bin + +setWindowTitle() { + echo -ne "\e]2;$*\a" +} +updateWindowTitle() { + setWindowTitle "${HOSTNAME%%.*}:${PWD/$HOME/~}" +} +PROMPT_COMMAND=$PROMPT_COMMAND updateWindowTitle + +function findHere() { ex=$1; shift; grep -R $* $ex .;} + diff --git a/gnome-terminal b/gnome-terminal new file mode 100755 index 0000000..7bd0cde --- /dev/null +++ b/gnome-terminal @@ -0,0 +1,2 @@ +#!/bin/bash +one-window 'gnome-terminal' 'xdotool windowfocus $WID & xdotool key ctrl+shift+t' diff --git a/goear.sh b/goear.sh new file mode 100755 index 0000000..520a3d0 --- /dev/null +++ b/goear.sh @@ -0,0 +1,70 @@ +#bin/bash +resultado=/tmp/resultado +canciones=/tmp/canciones +enlaces=/tmp/enlaces +titulos=/tmp/titulos +#Pedimos al usuario el titulo de la canción. +echo "Introduce el título de la canción o del artista:" +read TITULO + +if [ ! -d "goear" ] +then + mkdir goear +fi +#Descargamos el PHP correspondiente al título. +wget http://goear.com/search.php?q="$TITULO" -O $resultado + +#La línea 130 contiene todos los enlaces a goear... de risa pero bueno. +head -130 $resultado | tail -1 > $canciones + +#Mediante ER, obtenemos una lista de canciones y una lista de enlaces. +egrep -o 'listen/......./[^"]*' $canciones > $enlaces +egrep -o '"Escuchar[^"]*' $canciones > $titulos + +#Mostramos al usuario los que ha encontrado en la primera página. +Linea=1 +cat $titulos | while read line; + do { + echo $Linea: ${line:9} + let 'Linea += 1' + } + done + +#Si no encuentra nada, sale. +CONDICION=`wc -l $titulos | awk '{print $1}'` +if [ $CONDICION == 0 ]; then + echo "No hay resultados. Prueba buscando otra cosa." + rm $resultado $canciones $enlaces $titulos + exit +fi + +#Leemos qué canción quiere el usuario bajarse. +echo "¿Cuál te quieres bajar? Indica el número:" +read NUMERO + +#Concatenamos http://www.goear.com con el contenido de aBajar.txt. +#PD: Alguien sabe hacerlo de manera más sencilla? +GOEAR=http://www.goear.com/ +aBajar=`head -$NUMERO $enlaces | tail -1` +for LISTEN in $aBajar +do + ENLACE=${GOEAR}${LISTEN} +done +echo $ENLACE + +#A partir de aquí el script no es mío, pero es muy sencillo de leer. +fileid=`echo $ENLACE | cut -d '/' -f 5` +xmlurl="http://www.goear.com/tracker758.php?f="$fileid +infoline=`wget -qO- $xmlurl | grep ".mp3"` +mp3url=`echo $infoline | cut -d '"' -f6` +artist=`echo $infoline | cut -d '"' -f10` +title=`echo $infoline | cut -d '"' -f12` +filename=goear/"$artist-$title.mp3" +wget $mp3url -O "$filename" +rm $resultado $canciones $enlaces $titulos + +echo "¿Quieres reproducirla?[Y/n]" +read RES +if [ -z "$RES" -o "$RES" = "Y" -o "$RES" = "y" ];then + mplayer "$filename"; +fi; diff --git a/one-instance b/one-instance new file mode 100755 index 0000000..acd8ac6 --- /dev/null +++ b/one-instance @@ -0,0 +1,25 @@ +#!/bin/bash +if [ "x$1" != "x" ] +then + pgrep -l -u "$USER" -f "$1" | egrep -v "/bin/bash|/bin/sh" | grep -vq "$$" + if [ $? == "0" ] + then + ps aux | grep terminator > /home/balkian/LOG + WID=`xdotool search --class $1 | head -1` + wmctrl -i -a $WID + if [ "x$2" != "x" ] + then + eval "$2" + fi + else + if [ "x$3" == "x" ] + then + /usr/bin/$1 + else + eval "$3" + fi + fi +else + echo "Usage: one-instance program-name [extra action]" +fi + diff --git a/one-instance (copy) b/one-instance (copy) new file mode 100755 index 0000000..d0f7e95 --- /dev/null +++ b/one-instance (copy) @@ -0,0 +1,27 @@ +#!/bin/bash +if [ "x$1" != "x" ] +then + pgrep -fx $1 1> /dev/null + if [ $? == "0" ] + then + echo "running" + ps aux | grep terminator > /home/balkian/LOG + WID=`xdotool search --class $1 | head -1` + wmctrl -i -a $WID + if [ "x$2" != "x" ] + then + eval "$2" + fi + else + if [ "x$3" == "x" ] + then + echo "not running" + /usr/bin/$1 + else + eval "$3" + fi + fi +else + echo "Usage: one-instance program-name [extra action]" +fi + diff --git a/one-terminator.sh b/one-terminator.sh new file mode 100755 index 0000000..3cd18b4 --- /dev/null +++ b/one-terminator.sh @@ -0,0 +1,10 @@ +#!/bin/bash +pgrep -u "$USER" gnome-terminal | grep -qv "$$" +if [ "$?" == "0" ]; then + WID=`xdotool search --class "terminator" | head -1` + xdotool windowfocus $WID + xdotool key ctrl+shift+t + #wmctrl -i -a $WID +else + /usr/bin/gnome-terminal +fi diff --git a/one-window b/one-window new file mode 100755 index 0000000..e7c919e --- /dev/null +++ b/one-window @@ -0,0 +1,25 @@ +#!/bin/bash +if [ "x$1" != "x" ] +then + WID=`xdotool search --class $1 | head -1` + if [ "s$WID" != "s" ] + then + ps aux | grep terminator > /home/balkian/LOG + + wmctrl -i -a $WID + if [ "x$2" != "x" ] + then + eval "$2" + fi + else + if [ "x$3" == "x" ] + then + /usr/bin/$1 + else + eval "$3" + fi + fi +else + echo "Usage: one-instance program-name [extra action]" +fi + diff --git a/start-eclipse.sh b/start-eclipse.sh new file mode 100644 index 0000000..b2ccd8b --- /dev/null +++ b/start-eclipse.sh @@ -0,0 +1,17 @@ +#!/bin/bash +cd $(dirname $(dirname $0)) +eclipse/eclipse -vm jre1.6.0_20/bin/ || failed=1 +if [ $failed -eq 1 ]; then + + zenity --warning --title "Error executing eclipse's launcher" --text "Eclipse couldn't be found in $(pwd), please, modify $0 script to point to the right location" || exit + file=$(zenity --file-selection --title "Select the right executable"); + vm=$(zenity --file-selection --title "Select virtual machine"); + + echo $file; + if [ -n "$file" ]; then + if [ -n "$vm" ]; then + virt=" -vm $vm"; + fi + $file $virt + fi +fi diff --git a/terminator b/terminator new file mode 100755 index 0000000..e0cde22 --- /dev/null +++ b/terminator @@ -0,0 +1,2 @@ +#!/bin/bash +one-window "terminator" "xdotool windowfocus \$WID & xdotool key ctrl+shift+t;" "/usr/bin/terminator $*"