Skip to content

Instantly share code, notes, and snippets.

@ManuelBlanc
Last active February 20, 2017 14:40
Show Gist options
  • Save ManuelBlanc/9185599 to your computer and use it in GitHub Desktop.
Save ManuelBlanc/9185599 to your computer and use it in GitHub Desktop.
Instalador de Sublime Text 3 para los laboratorios de la EPS

Instalador de Sublime Text 3

Este script establece Sublime Text 3 como editor por defecto del sistema. Comprueba si esta instalado en ~/UnidadH/sublime_text_3, y en caso instalado lo descarga e instala ahi. Hay dos modos:

Para uso frecuente

Descarga este script a tu UnidadH y dale permisos de ejecuccion:

cd ~/UnidadH
curl -O https://gist.githubusercontent.com/ManuelBlanc/9185599/raw/InstallSublime.sh
chmod u+x InstallSublime.sh

Para arrancar sublime, haz doble clic en el script y se instalara/configurara si es necesario.

Para un solo uso

Si necesitas un Sublime aqui y ahora, copia esta linea en una terminal:

bash <(curl -fsSL https://gist.githubusercontent.com/ManuelBlanc/9185599/raw/InstallSublime.sh)

Licencia

The MIT License (MIT)

Copyright (c) 2015 ManuelBlanc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#!/bin/sh
# Instalador de Sublime Text 3 para los laboratorios de la EPS (v3.0)
# Vease: https://gist.github.com/ManuelBlanc/9185599
# ----------------------------------------------------------------------------
# The MIT License (MIT)
# Copyright (c) 2015 ManuelBlanc
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# ----------------------------------------------------------------------------
{ # Proteccion para evitar una ejecuccion parcial (eg. por error al hacer curl)
set -eu # Modo sano
# Variables de configuracion
BITS=$(getconf LONG_BIT)
SUBLIME_URL="http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_3083_x$BITS.tar.bz2"
PKGCTRL_URL='https://packagecontrol.io/Package Control.sublime-package'
INSTALL_BASE="$HOME/UnidadH"
INSTALL_PATH="$INSTALL_BASE/sublime_text_3"
# Formateo
NORMAL=$(tput sgr0)
BOLD=$(tput bold)
# Utilidades
INFO() { echo "==> $BOLD$1$NORMAL"; }
abort() { INFO "error: $1"; exit 1; }
# ----------------------------------------------------------------------------
## Instala sublime portatil
install_sublime() {
local TMP_FILE=$(mktemp -t 'InstallSublime.XXXXXXXX')
INFO "Comprobando que se pueda instalar"
cd "$INSTALL_BASE" || abort "no se pudo cambiar al directorio de instalacion ($INSTALL_BASE)"
[ -w "$(pwd)" ] || abort "no hay permiso de escritura"
[ ! -e sublime_text_3 ] || abort "ya existe un fichero llamado sublime_text_3 en $INSTALL_BASE"
INFO "Descargando Sublime Text 3"
curl "$SUBLIME_URL" -o "$TMP_FILE"
INFO "Extrayendo"
tar -vxjf "$TMP_FILE"
rm "$TMP_FILE"
INFO "Convirtiendo la instalacion en portable"
mkdir -vp 'sublime_text_3/Data'
mkdir -vp 'sublime_text_3/Data/Installed Packages'
INFO "Descargando Package Control"
curl "$PKGCTRL_URL" -o 'sublime_text_3/Data/Installed Packages/Package Control.sublime-package'
INFO "Instalacion finalizada."
}
## Establece Sublime como editor por defecto
config_sublime() {
local IFS
# Creamos la carpeta de asociaciones (si no existe)
mkdir -vp ~/.local/share/applications/
INFO "Generando sublime_text.desktop"
sed -e "s:/opt/sublime_text/:$INSTALL_PATH/:" -e "s:^Icon=sublime-text$:Icon=$INSTALL_PATH/Icon/256x256/sublime-text.png:" "$INSTALL_PATH/sublime_text.desktop" > "$HOME/.local/share/applications/sublime_text.desktop"
chmod u+x ~/.local/share/applications/sublime_text.desktop
INFO "Generando mimeapps.list"
echo '[Default Applications]' > ~/.local/share/applications/mimeapps.list
grep 'gedit' '/etc/gnome/defaults.list' | sed 's/gedit/sublime_text/g' >> ~/.local/share/applications/mimeapps.list
# Lista copiada tal cual de /usr/share/applications/emacs24.desktop
# Quiza seria mejor buscar los .desktop con la linea GenericName=Text Editor ?
EMACS_MIME_LIST='text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++'
IFS=';'
for MIME in $EMACS_MIME_LIST; do
echo "$MIME=sublime_text.desktop" >> ~/.local/share/applications/mimeapps.list
done
INFO "Configuracion finalizada."
}
[ -d "$INSTALL_PATH" ] || install_sublime
[ -f "$HOME/.local/share/applications/sublime_text.desktop" ] || config_sublime
$INSTALL_PATH/sublime_text "$@"
} # Fin de la proteccion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment