Skip to content

Instantly share code, notes, and snippets.

@ptomasroos
Created December 3, 2013 13:15
Show Gist options
  • Save ptomasroos/7768959 to your computer and use it in GitHub Desktop.
Save ptomasroos/7768959 to your computer and use it in GitHub Desktop.
Install sublime-text-2 properly on Fedora 19 with Gnome 3 icon
#!/usr/bin/env bash
# Usage: {script} [ OPTIONS ] TARGET VERSION
#
# TARGET Default target is "/usr/local".
# VERSION If not defined tries to get the build into the Sublime Text 2 website.
#
# OPTIONS
#
# -h, --help Displays this help message.
#
# Report bugs to Henrique Moody <henriquemoody@gmail.com>
#
set -e
if [[ "${1}" = '-h' ]] || [[ "${1}" = '--help' ]]; then
sed -E 's/^#\s?(.*)/\1/g' "${0}" |
sed -nE '/^Usage/,/^Report/p' |
sed "s/{script}/$(basename "${0}")/g"
exit
fi
declare URL
declare URL_FORMAT="http://c758482.r82.cf2.rackcdn.com/%s.tar.bz2"
declare PACKAGE="Sublime Text"
declare TARGET="${1:-/usr/local}"
declare VERSION="${2}"
declare BITS=$(uname -m)
if [[ -z "${VERSION}" ]]; then
VERSION=$(
curl -Ls http://www.sublimetext.com/2 |
grep '<h2>Version' |
head -n1 |
sed -E 's#<h2>Version ([0-9.]+)</h2>#\1#g'
)
fi
PACKAGE+=" ${VERSION}"
if [[ "${BITS}" = "x86_64" ]]; then
PACKAGE+=" x64"
fi
URL=$(printf "${URL_FORMAT}" "${PACKAGE}" | sed 's/ /%20/g')
read -p "Do you really want to install \"${PACKAGE}\" on \"${TARGET}\"? [Y/n]: " CONFIRM
CONFIRM=$(echo "${CONFIRM}" | tr [a-z] [A-Z])
if [[ "${CONFIRM}" = 'N' ]] || [[ "${CONFIRM}" = 'NO' ]]; then
echo "Aborted!"
exit
fi
echo "Downloading ${PACKAGE}"
curl -L "${URL}" | tar -xjC ${TARGET}
mv "${TARGET}/Sublime Text 2/" "${TARGET}/sublime_text_2"
echo "Creating binary file"
cat > ${TARGET}/bin/subl <<SCRIPT
#!/bin/sh
if [ \${1} == \"--help\" ]; then
${TARGET}/sublime_text_2/sublime_text --help
else
${TARGET}/sublime_text_2/sublime_text \$@ > /dev/null 2>&1 &
fi
SCRIPT
echo "Creating shortcut file"
cat > "/usr/share/applications/sublime-text-2.desktop" <<SHORTCUT
[Desktop Entry]
Name=Sublime Text 2
Comment=Edit text files
Exec=/usr/local/sublime_text_2/sublime_text
Icon=/usr/local/sublime_text_2/Icon/128x128/sublime_text.png
Terminal=false
Type=Application
Encoding=UTF-8
Categories=Utility;TextEditor;
SHORTCUT
echo "Finish!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment