Tips and Tricks About Computers, Web Development, Linux, the Internet and the Like
Ubuntu
Tips for Using Bash in the Linux Terminal – Part 1
Oct 23rd
Posted by Tyler Mulligan in Bash
Introduction
Bash is the default shell in the terminal on many Linux and UNIX based operating system, such as Ubuntu or Mac OS X. I’ve mentioned commandlinefu.com before as a great reference for learning some neat tricks with the terminal. I’ve gained a lot from the site and a few others, such as the Advanced Bash Scripting Guide and the bash hackers wiki. I wanted to share some of the tips I use most often, combined with other information that I’ve compiled through my use of the terminal.
I think I should mention that I’ve been using more applications in the terminal recently. Some people view this as backwards but I argue just the opposite. Limiting the amount of times I need to use the mouse and the number of keystrokes I need to make drastically increases my efficiency. Many bash applications are designed around single keystrokes, layered hotkeys and edit “modes”. GUIs have their place but many of my tasks can be completely more accurately and consistently via the terminal.
With that said, lets dive in.
The Basics
Hotkeys
Moving:
Ctrl + a -> Go to the beginning of the line you are currently typing on.
Ctrl + e -> Go to the end of the line you are currently typing on
Alt + f -> Move cursor forward one word on the current line.
Alt + b -> Move cursor backward one word on the current line.
Editing:
Ctrl + u -> Clears from before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + k -> Clear from after the cursor. If you are at the beginning of the line, clears the entire line.
Ctrl + w -> Delete the word before the cursor.
Ctrl + h -> Same as backspace.
Ctrl + t -> Swap the last two characters before the cursor.
Esc + t -> Swap the last two words before the cursor.
Other:
Ctrl + l -> Clear screen (same as clear command).
Ctrl + c -> Kill the current command or process.
Ctrl + z -> Puts whatever you are running into a suspended background process, fg to restore it.
Ctrl + d -> Exit the current shell.
Oddly, unlike many terminal applications, Bash hotkeys don’t make a lot of sense to me. There are very few that are “intuitive”.
History
Press the up arrow for the last command or:
!! — repeat last command
echo "hello" !!
Outputs:
z@zentury:~$ echo "hello" hello z@zentury:~$ !! echo "hello" hello
ctrl+r is one of the best ways to search through your history. it will initialize a reverse search as you type. To go to the next result, press ctrl+r again
Advanced
History Expansion/Modification
!:0 — will repeat the first token
cd ~ ls -la !:0
!:1-3 — defining a range: 1-3 will repeat the 2nd to 4th tokens (count starts at 0). It’s important to note that double quotes will group tokens together.
echo "hello there" && ls ~ !:3-4
!!:s/find/replace/ — will allow you to replace a part of the command
echo "hello there" !!:s/hello/hi/
Outputs:
z@zentury:~$ echo "hello there" hello there z@zentury:~$ !!:s/hello/hi/ echo "hi there" hi there
OR even shorter:
^find^replace
echo "hello there" ^hello^hi
Outputs:
z@zentury:~$ echo "hello there" hello there z@zentury:~$ ^hello^hi echo "hi there" hi there
Sequences and Pattern Expansion
Typically in a Linux or UNIX environment you have access to a command line tool name “seq” which gone over before. However, it’s good to know that bash has built-in sequence expansion and you don’t need to rely on seq.
echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y zby defining a start and end character with the ‘..’ in between, we tell bash to fill in the rest and echo a list for us. Those are all lowercase, what if you wanted uppercase? simple:
echo {A..Z}
A B C D E F G H I J K L M N O P Q R S T U V W X Y ZOr both, with a few extra characters in the mix:
echo {A..z}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y zIt doesn’t always have to be a-z though,
echo {A..G}
A B C D E F GThis also works with numbers:
echo {0..9}
0 1 2 3 4 5 6 7 8 9
echo {0..100}
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100Descending as well as ascending
echo {9..0}
9 8 7 6 5 4 3 2 1 0Echo a specific set
echo {1,4,6,9}
1 4 6 9Applying it
Quickly backup a file
touch file1.txt
cp file1.txt{,.bak}
ls
file1.txt file1.txt.bakexplanation: the first parameter is empty, the second is .bak, this expands to >> cp file1.txt file1.txt.bak << and creates the copy
Convert an image type
If you have image magick installed, you can convert file types pretty easy using this same concept:
sudo apt-get install imagemagick
(To install on Ubuntu)
convert file.{jpg,png}Permutations
echo {a..c}{a..c}{a..c}
aaa aab aac aba abb abc aca acb acc baa bab bac bba bbb bbc bca bcb bcc caa cab cac cba cbb cbc cca ccb cccStay tuned for Part 2
These are some pretty common techniques I use to reduce the amount of typing and thinking required to complete a task in the terminal. Stay tuned for part 2 and check out some of my creative usages at commandlinefu.com.
-
Sorry screen, tmux is better (but here are some screen-like hotkeys)
Oct 18th
Posted by Tyler Mulligan in Computers
Introduction
If you’re familiar with the command line on Linux or UNIX, you’ve likely heard of a program called “screen”, which allows you to create virtual terminal sessions inside of your current terminal. The major benefit to this is the ability to dettach and reattach screen sessions, leaving your programs to act as if you never left. Additionally, you can have multiple buffers inside your screen that act like tabs, allowing you to flip between.
The major difference between screen and tmux is their ability to split and manage splits. Oh yeah, that and hotkeys. I think they were trying to pay legacy (or force you to change back :-P) by setting up your main key to be “b” instead of “a”, which is an awkward reach. Tux Wears Fedora below shares more screen like hotkeys, as do I with some minor tweaks that I combined with the default example in ubuntu /usr/share.
I became well acquainted at Tux Wears Fedora’s post on tmux migrating from screen.
# ~/.tmux.conf # By Tyler Mulligan. Public domain. # # This configuration file binds many of the common GNU screen key bindings to # appropriate tmux key bindings. Note that for some key bindings there is no # tmux analogue and also that this set omits binding some commands available in # tmux but not in screen. # # Note this is a good starting point but you should check out the man page for more # configuration options if you really want to get more out of tmux ### Unbind existing tmux key bindings (except 0-9). # Set the prefix to ^A. unbind C-b set -g prefix ^A bind a send-prefix # Bind appropriate commands similar to screen. # lockscreen ^X x unbind ^X bind ^X lock-server unbind x bind x lock-server # screen ^C c unbind ^C bind ^C new-window bind c bind c new-window # detach ^D d unbind ^D bind ^D detach # displays * unbind * bind * list-clients # next ^@ ^N sp n unbind ^@ bind ^@ next-window unbind ^N bind ^N next-window unbind " " bind " " next-window unbind n bind n next-window # title A unbind A bind A command-prompt "rename-window %%" # other ^A unbind ^A bind ^A last-window # prev ^H ^P p ^? unbind ^H bind ^H previous-window unbind ^P bind ^P previous-window unbind p bind p previous-window unbind BSpace bind BSpace previous-window # windows ^W w unbind ^W bind ^W list-windows unbind w bind w list-windows # quit \ unbind \ bind \ confirm-before "kill-server" # kill K k unbind K bind K confirm-before "kill-window" unbind k bind k confirm-before "kill-window" # redisplay ^L l unbind ^L bind ^L refresh-client unbind l bind l refresh-client # More straight forward key bindings for splitting unbind % bind | split-window -h bind v split-window -h unbind '"' bind - split-window -v bind h split-window -v # History set -g history-limit 1000 # Pane unbind o bind C-s down-pane # Terminal emulator window title set -g set-titles on set -g set-titles-string '#S:#I.#P #W' # Status Bar set -g status-bg black set -g status-fg white set -g status-interval 1 set -g status-left '#[fg=green]#H#[default]' set -g status-right '#[fg=yellow]#(cut -d " " -f 1-4 /proc/loadavg)#[default] #[fg=cyan,bold]%Y-%m-%d %H:%M:%S#[default]' # Notifying if other windows has activities setw -g monitor-activity on set -g visual-activity on # Highlighting the active window in status bar setw -g window-status-current-bg red # Clock setw -g clock-mode-colour green setw -g clock-mode-style 24 # :kB: focus up unbind Tab bind Tab down-pane unbind BTab bind BTab up-pane # " windowlist -b unbind '"' bind '"' choose-window
Splitting is what initially caused me to migrate but there are plenty of other features that have lead me to stay. this article outlines the benefits in detail. Once you go tmux, you never go back.
Using Terminal Program "screen" on Linux / UNIX
Oct 18th
Posted by Tyler Mulligan in Command Line
Introduction
The terminal program “screen” for Linux / UNIX, is a command line tool that allows you to emulate terminals inside a currently running session and detach the ‘screen’ to the background. This program may seem obscure to new users because of it’s abstract nature and unusual key bindings but once you start learning the basics, the advanced usages don’t seem that scary.
If you consider yourself to have an advanced sense of the command line and you’d like to go more advanced out of gate, you should consider skipping ahead to my article on the screen successor, tmux which allows for more advanced splitting (and apparently better code).
Getting Started
Below is a walk through of an average screen scenario I’ve put together to give you an idea of how you might use this program in your workflow.
to start a basic screen session type:
screen
this will put you in a virtual session.
to detach the screen press: ctrl+a, d
to reattach the screen type:
screen -r
detach again, then type:
screen
and detach this. You now have 2 screen sessions open, so when you type screen -r, instead of reattaching, it will list the possible screens to attach. You’ll see something like the following:
There are several suitable screens on:
31454.pts-2.quadjutsu (10/10/2009 09:45:51 AM) (Detached)
31219.pts-2.quadjutsu (10/10/2009 09:44:27 AM) (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
So I’d type:
screen -r 31454
to attach the first one. On systems with ‘pkill’ you can type:
pkill screen
to kill all the screen sesions.
That’s one way to separate screens… another is virtual “tabs” within a screen session.
so lets create a new screen session with:
screen
Then type:
ls
so you have some data to reference for which “tab” you’re in
Then hit: ctrl+a, c
This will create a new tab.
to cycle forward through the tabs (next), hit: ctrl+a, n or ctrl+a, [spacebar]
to cycle backwards through the tabs (previous), hit: ctrl+a, p or ctrl+a, [backspace]
to kill a tab, type: exit
I found a good reference for “screen” hotkeys at pixelbeat.org if you’d like to learn more.
Restricting a user’s shell permissions on Ubuntu Server 10.04 with lshell
Sep 27th
Posted by Tyler Mulligan in Bash
As described by apt-cache, the method which I usually begin a package search for in a Ubuntu Server 10.04 environment:
z@zentury ~$ apt-cache search lshell lshell - restricts a user's shell environment to limited sets of commands
This is an extremely useful way to restrict a Linux users capabilities. Alternative shells, such as rssh, limit you to toggle a specific set of applications, (scp, sftp, cvs, svn, rsync or rdist). A limited shell is helpful for reasons such as backups or game/application servers where you know/want the user to be able to execute only a specific set of actions. You can however, consider other reasons for restricting users on a Linux based machine.
A typical use case is provided in the lshell wiki.
Ubuntu also provides a default in etc/lshell.conf, which serves as a good example:
# lshell.py configuration file
#
# $Id: lshell.conf,v 1.20 2009/06/09 19:53:46 ghantoos Exp $
[global]
## log directory (default /var/log/lshell/ )
logpath : /var/log/lshell/
## set log level to 0, 1, 2 or 3 (0: no logs, 1: least verbose)
loglevel : 2
## configure log file name (default is %u i.e. username.log)
#logfilename : %y%m%d-%u
[default]
## a list of the allowed commands or 'all' to allow all commands in user's PATH
allowed : ['ls','echo','cd','ll']
## a list of forbidden character or commands
forbidden : [';', '&', '|','`','>','<', '$(', '${']
## number of warnings when user enters a forbidden value before getting
## exited from lshell
warning_counter : 2
## command aliases list (similar to bash’s alias directive)
aliases : {'ll':'ls -l', 'vi':'vim'}
## a value in seconds for the session timer
#timer : 5
## list of path to restrict the user "geographicaly"
#path : ['/home/bla/','/etc']
## set the home folder of your user. If not specified the home_path is set to
## the $HOME environment variable
#home_path : '/home/bla/'
## update the environment variable $PATH of the user
#env_path : ':/usr/local/bin:/usr/sbin'
## allow or forbid the use of scp (set to 1 or 0)
#scp : 1
## allow of forbid the use of sftp (set to 1 or 0)
#sftp : 1
## list of command allowed to execute over ssh (e.g. rsync, rdiff-backup, etc.)
#overssh : ['ls', 'rsync']
## logging strictness. If set to 1, any unknown command is considered as
## forbidden, and user's warning counter is decreased. If set to 0, command is
## considered as unknown, and user is only warned (i.e. *** unknown synthax)
#strict : 1
## force files sent through scp to a specific directory
#scpforce : '/home/bla/uploads/'
If this looks like something you would like to be able to do, you can install it with apt-get:
z@zentury ~$ apt-get install lshell
You can change a current user to have the limited shell with the following command:
sudo chsh -s /usr/bin/lshell backupbot
You can add a new user with a limited shell with the following command (-m creates the home directory):
sudo useradd -m -s /usr/bin/lshell backupbot
scp-notifications for GNOME and Ubuntu – Expanding on My Original Python Script
Jun 26th
Posted by Tyler Mulligan in Compiz
I’ve only been coding Python for ~12 hours total, so don’t expect this to be perfect. Knowing what I know about creating/testing other software and doing my best to scour through very light pynotify documentation, I’ve begun to build out this script to be more useful / portable / configurable. As the Version 0.6 indicates, I’m not quite at my goal yet and there is still more to learn to bring it up to that point.
I’m releasing this early on my blog just in case I caught any people yesterday who’ve been experimenting with my research / code so far. I’ll share it on github when I evolve it just a bit more.
#!/usr/bin/env python
#
# Title: scp-notifications
# Author: Tyler Mulligan (tyler@detrition.net)
# Date: 06/26/2010
# Version: 0.6
# Description:
# Used in combination with an event, such as an action or cronjob, this script
# will scp the latest file from a folder to your server.
#
# Optionally, it can copy the url to your clipboard and/or show a popup with a
# link to the file after succesfully uploading
#
# Orginally developed to be piped to from compiz screenshot tool
# http://interwebninja.com/videos/compiz-screenshot-piped-to-notification-daemon-for-upload.ogv
#
# The MIT License
#
# Copyright (c) 2010 Tyler Mulligan
#
# 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
#
import pygtk
pygtk.require('2.0')
import pynotify
import gtk
import sys
import os
import subprocess
# Set Variables
#####################################
user = "user"
host = "server.com"
# All should have trailing slashes
lfolder = "/home/user/screenshots/"
hfolder = "/home/remote_user/screenshots/"
httplink = "http://"+host+"/screenshots/"
# Display
#####################################
t1 = 5000 # timeout for screenshot upload dialog
t2 = 3000 # timeout for screenshot preview
t3 = 7000 # timeout for link dialog
screenshot_preview = 1 # If using with the compiz screenshot plugin, you may want this
popup_link = 1 # another popup
copy_to_clipboard = 0 # automatically copy text to keyboard
# Position
#####################################
# Get screensize < < used for relative positioning
display = gtk.gdk.display_get_default()
screen = display.get_default_screen()
x = screen.get_width() - 1
y = screen.get_height() - 1
# 0 for Automatic Placement
"""
x1 = 0
y1 = 0
x2 = 0
y2 = 0
x3 = 0
y3 = 0
"""
# Define Relative Position (assuming top-right)
x1 = x-1
y1 = 12
x2 = x1
y2 = y1 + 100
x3 = x-1
y3 = 12
# Define Static (1920 puts it on my second monitor)
"""
x1 = 1919
y1 = 12
x2 = x1
y2 = y1 + 100
x3 = 1920
y3 = 12
"""
#####################################
def upload_cb(n, action):
assert action == "upload"
subprocess.call(["scp", os.path.join(lfolder, f), '%s@%s:%s' % (user, host, hfolder)])
# setup URL in
if copy_to_clipboard:
clipboard = gtk.clipboard_get()
clipboard.set_text(httplink + f)
# make our data available to other applications
clipboard.store()
# Notification: Link for the clicking
if popup_link:
n3 = pynotify.Notification("Here is your link","<a href='" + httplink + f + "'>" + httplink + f + "")
helper = gtk.Button()
icon = helper.render_icon(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG)
n3.set_icon_from_pixbuf(icon)
n3.set_urgency(pynotify.URGENCY_NORMAL)
if x3:
n3.set_hint("x", x3)
if y3:
n3.set_hint("y", y3)
n3.set_timeout(t3)
n3.connect("closed",closen3_cb)
if not n3.show():
print "Failed to send notification"
sys.exit(1)
closen1_cb(n1)
closen2_cb(n2)
gtk.main_quit()
sys.exit(1)
# Notification 1 was closed
def closen1_cb(n):
n1.close()
if screenshot_preview:
n2.close()
gtk.main_quit()
# Notification 2 was closed
def closen2_cb(n):
n2.close()
gtk.main_quit()
# Notification 2 was closed
def closen3_cb(n):
n3.close()
gtk.main_quit()
# The Ignore button was clicked
def ignore_cb(n, action):
assert action == "ignore"
closen1_cb(n1)
closen2_cb(n2)
gtk.main_quit()
# Main
def main():
gtk.main()
# Init
if __name__ == '__main__':
if not pynotify.init("Notifier 'scp' Option"):
sys.exit(1)
# Get latest file and build uri
start = os.path.abspath(lfolder)
f = max([(os.path.getmtime(os.path.join(start,p)),p)
for p in os.listdir(start)])[1]
uri = lfolder + f
# Notification: Upload to Server
n1 = pynotify.Notification("Upload to Server?","Copy the file '" + f + "' to the server?")
helper = gtk.Button()
icon = helper.render_icon(gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG)
n1.set_icon_from_pixbuf(icon)
n1.set_urgency(pynotify.URGENCY_NORMAL)
if x1:
n1.set_hint("x", x1)
if y1:
n1.set_hint("y", y1)
n1.set_timeout(t1)
n1.add_action("upload", "Yes, Upload", upload_cb)
n1.add_action("ignore", "Ignore", ignore_cb)
n1.connect("closed",closen1_cb)
if not n1.show():
print "Failed to send notification"
sys.exit(1)
# Notification: Screenshot Preview
if screenshot_preview:
n2 = pynotify.Notification("Screenshot Preview", "", uri)
n2.set_urgency(pynotify.URGENCY_LOW)
if x2:
n2.set_hint("x", x2)
if y2:
n2.set_hint("y", y2)
n2.set_timeout(t2)
n2.connect("closed",closen2_cb)
if not n2.show():
print "Failed to send notification"
sys.exit(1)
main()
.
Ubuntu Notifications (osd-notify) Sucks, notifications-daemon Rocks – Exploiting the Goodness with Compiz
Jun 25th
Posted by Tyler Mulligan in Compiz
Introduction
The long name for this blog used to be “Tyler Mulligan’s Tips and Tricks for Increasing your Efficiency“. I love finding ways to increase my efficiency and let computers do the work while I focus on more interests aspects of what the computer is providing me with. When I recognize an issue, I find a way to cut out time by streamlining the process for the most accurate repetition, like any programmer would/should/could.
I noticed myself taking a lot of screenshots with compiz’ built in screenshot tool (I can hold a hotkey and drag a box to take newspaper style clippings). This is very fast and simple, I highly recommend enabling this option and getting used to it. However, I don’t care much for clicking around on clunky websites to upload images.
This is where my adventure starts… when I find out a very useful feature was deprecated and not replaced in Ubuntu. I don’t use the new notification area, it has too much I don’t need, I never liked the behavior of these new osd-notify notifications which I found out now are even more worthless (sorry team).
Using Sane Notifications in Ubuntu
After reinstalling the GNOME default notifications system in Ubuntu I was able to use SANE notifications that actually… KICK ASS! I don’t understand how osd-notify is better than these which even comes with it’s own notification properties panel. Maybe it’s an under the hood thing…
Regardless, there is no doubt in my mind that notifications that you hover, can still slightly see but click through but cannot perform any actions, even a close, are just plan stupid and annoying..

Screenshot of the script I ended up writing using the “better” notification system to ask me if I want to upload the screenshot I just took to the server.
Linking the notifications
I linked the notifications the following way:

Python Script for Notification that Prompts for File Upload to Server
Knowing diddly squat about Python, I chugged forward with my classic notification popups that allow for interaction as it had the most activity around it and some examples available in /usr/share/doc/python-notify/examples/
I ended coming up with the following script thanks to some help from a few people in #python on irc.freenode.org
This is outside of the scope of this blogpost but this script assumes you have setup passwordless ssh to your server.
#!/usr/bin/env python
#
# Title: Notification 'scp' Option
# Author: Tyler Mulligan (tyler@detrition.net)
# Date: 06/25/2010
# Description:
# Used in combination with an event, such as an action or cron
# the latest file from a folder will be scped to your server and will copy
# the http location of the that file to your clipboard
#
# Orginally developed to be piped to from compiz screenshot tool
#
#
# The MIT License
#
# Copyright (c) 2010 Tyler Mulligan
#
# 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
#
import pygtk
pygtk.require('2.0')
import gtk
import pynotify
import sys
import os
import subprocess
user = "user"
host = "server.com"
lfolder = "/home/user/screenshots/"
hfolder = "/home/remote_user/screenshots/"
httplink = "http://"+host+"/screenshots/"
timeout = 5000
# Set position
display = gtk.gdk.display_get_default()
screen = display.get_default_screen()
x = screen.get_width() - 1
y = screen.get_height() - 1
#x = 1919
#y = 12
def upload_cb(n, action):
assert action == "upload"
start = os.path.abspath(lfolder)
f = max([(os.path.getmtime(os.path.join(start,x)),x)
for x in os.listdir(start)])[1]
# setup URL in clipboard
clipboard = gtk.clipboard_get()
clipboard.set_text(httplink + f)
# make our data available to other applications
clipboard.store()
os.system('scp "%s" "%s@%s:%s"' % (lfolder + f, user, host, hfolder) ).wait()
n.close()
gtk.main_quit()
def ignore_cb(n, action):
assert action == "ignore"
n.close()
gtk.main_quit()
if __name__ == '__main__':
if not pynotify.init("Notifier 'scp' Option"):
sys.exit(1)
# Setup Popup
n = pynotify.Notification("Upload to Server?")
n.set_urgency(pynotify.URGENCY_NORMAL)
n.set_timeout(timeout)
n.set_category("device")
n.add_action("upload", "Yes, Upload", upload_cb)
n.add_action("ignore", "Ignore", ignore_cb)
# Set position
n.set_hint("x", x)
n.set_hint("y", y)
if not n.show():
print "Failed to send notification"
sys.exit(1)
gtk.main()
edit: I updated the script with some position information — I love that I can put the notifications ANYWHERE on my screen. I also variablized the timeout.
edit 2: Here is a video of my improved script in action — I’ll post the source later
http://interwebninja.com/videos/compiz-screenshot-piped-to-notification-daemon-for-upload.ogv
Going Beyond
The Compiz example is just something that server my immediate needs. The possibilities are however endless. You can for example, link this script to a cron job asking you if you want to sync some other sort of file. Or perhaps you’d like to add multiple buttons to give yourself a folder / server choice.
Happy hacking
Reseting your system wide cursor theme in ubuntu
May 11th
Posted by Tyler Mulligan in Command Line
If you installed KDE in ubuntu (GNOME based), you may have noticed that when you log back into GNOME, you keep the KDE cursor theme. To fix this, use update-alternatives like so:
0025|z@zentury ~$ sudo update-alternatives --config x-cursor-theme There are 7 choices for the alternative x-cursor-theme (providing /usr/share/icons/default/index.theme). Selection Path Priority Status ------------------------------------------------------------ * 0 /etc/X11/cursors/oxy-white.theme 50 auto mode 1 /etc/X11/cursors/core.theme 30 manual mode 2 /etc/X11/cursors/handhelds.theme 20 manual mode 3 /etc/X11/cursors/oxy-white.theme 50 manual mode 4 /etc/X11/cursors/redglass.theme 20 manual mode 5 /etc/X11/cursors/whiteglass.theme 20 manual mode 6 /usr/share/icons/DMZ-Black/cursor.theme 30 manual mode 7 /usr/share/icons/DMZ-White/cursor.theme 50 manual mode Press enter to keep the current choice[*], or type selection number:
press “7″ for the default
Fastest way to install the media essentials in ubuntu
May 7th
Posted by Tyler Mulligan in Command Line
If you’re coming from Windows, or like me, find yourself living in a live CD while you figure out which step went wrong; you’ll be interested in the essential media codecs, flash, java, Microsoft fonts, etc.
I thought I’d share the way I did this as quickly as possible in in Ubuntu 10.04 using the command line.
Open up terminal, using ctrl+alt+t (Which I’m very happy about as this has been my default since 8.04). Alternativelty from the main menu -> Applications > Accessories > Terminal
Make a backup in case you’re scared, then remove the comments from repositories you need to unlock to access the restricted (proprietary) packages.
ubuntu@ubuntu:~$ sudo cp /etc/apt/sources.list . ubuntu@ubuntu:~$ sudo sed -i 's/^# deb/deb/' /etc/apt/sources.list
We do this be matching the first 2 characters with ‘# ‘ and replacing them with ” (nothing). See the diff below (> indicate original lines, < are changed).
ubuntu@ubuntu:~$ diff sources.list /etc/apt/sources.list 18,23c18,23 < # deb http://archive.ubuntu.com/ubuntu lucid universe < # deb-src http://archive.ubuntu.com/ubuntu lucid universe < # deb http://archive.ubuntu.com/ubuntu lucid-updates universe < # deb-src http://archive.ubuntu.com/ubuntu lucid-updates universe < # deb http://security.ubuntu.com/ubuntu lucid-security universe < # deb-src http://security.ubuntu.com/ubuntu lucid-security universe --- > deb http://archive.ubuntu.com/ubuntu lucid universe > deb-src http://archive.ubuntu.com/ubuntu lucid universe > deb http://archive.ubuntu.com/ubuntu lucid-updates universe > deb-src http://archive.ubuntu.com/ubuntu lucid-updates universe > deb http://security.ubuntu.com/ubuntu lucid-security universe > deb-src http://security.ubuntu.com/ubuntu lucid-security universe 30,35c30,35 < # deb http://archive.ubuntu.com/ubuntu lucid multiverse < # deb-src http://archive.ubuntu.com/ubuntu lucid multiverse < # deb http://archive.ubuntu.com/ubuntu lucid-updates multiverse < # deb-src http://archive.ubuntu.com/ubuntu lucid-updates multiverse < # deb http://security.ubuntu.com/ubuntu lucid-security multiverse < # deb-src http://security.ubuntu.com/ubuntu lucid-security multiverse --- > deb http://archive.ubuntu.com/ubuntu lucid multiverse > deb-src http://archive.ubuntu.com/ubuntu lucid multiverse > deb http://archive.ubuntu.com/ubuntu lucid-updates multiverse > deb-src http://archive.ubuntu.com/ubuntu lucid-updates multiverse > deb http://security.ubuntu.com/ubuntu lucid-security multiverse > deb-src http://security.ubuntu.com/ubuntu lucid-security multiverse > <pre class="brush:bash">
Now that we uncommented these lines, they will be read next time we update, so lets go ahead and do that now. Once that is done, we can install the extras.
ubuntu@ubuntu:~$ sudo apt-get update ubuntu@ubuntu:~$ sudo apt-get install ubuntu-restricted-extras
Rock and roll.
RabbitVCS is the new Nautilus SVN
May 4th
Posted by Tyler Mulligan in Computers
I should have written about this months ago. Readers have replied to my previous post about nautilus svn, which I claimed to be the first that didn’t suck. This is the evolution of it, RabbitVCS (Version Control System), which aims to use the same intuitive, integrated gui for other version control systems, such as git (check the rabbitvcs roadmap for details on expected support for different versioning system.
Packages for nautilus you wish were installed by default in ubuntu
May 4th
Posted by Tyler Mulligan in Application Management
Intro
Thanks to a tip I picked up at Tombuntu about nautilus, after following up on a trick to add files to mocp through nautilus scripts trackback link from Hilltop Yodler (great article), when doing a google search for GiS for nautilus-actions (apt-get install nautilus-actions). I learned about 3 kick ass additions to the nautilus menu. I realized Fedora Linux and Linux Mint had some of these in their context menus but didn’t make the connection to ubuntu until now.
On with the Show
sudo apt-get install nautilus-open-terminal nautilus-image-converter nautilus-gksu
for some kick ass options in the context (right click) menu of nautilus (your default file manager in ubuntu). For more information, check out the tombuntu article I linked above.
pkill nautilus
to restart nautilus and have the new packages in your context menu
More
If you’re interested in this, you’ll probably also like my article about nautilus-actions.

