Since this thread just popped back up, it reminded me that I made a small change to the above script that is worth sharing. I realized that I'm normally calling the script (which I call ask-link
BTW) from the command line or the Alt-F2
run dialog. So the zenity dialog is a bit redundant. So I first check to see if a package name is passed when calling the script and only show the dialog if it isn't.
#!/bin/bash
set -e
# Create link for installing packages on AskUbuntu. Source:
# http://meta.askubuntu.com/questions/548/how-to-post-links-that-install-software-via-apt
if [ -n "$1" ]; then
PACKAGE=$1
else
PACKAGE=$(zenity --entry --text="packagename")
fi
echo "[${PACKAGE}](http://packages.ubuntu.com/${PACKAGE}) [![Install ${PACKAGE}](http://bithostmar.lyco/software-large)](http://apt.ubuntu.com/p/${PACKAGE})" | xclip