Skip to content

Instantly share code, notes, and snippets.

@trnila
Created February 2, 2017 16:52
Show Gist options
  • Save trnila/3b1ee0af28e5aa0f028bd20f6564d97b to your computer and use it in GitHub Desktop.
Save trnila/3b1ee0af28e5aa0f028bd20f6564d97b to your computer and use it in GitHub Desktop.
Install package that is not found in Archlinux with packer

Copy attached file to ~/.local/share/cmd_not_found.sh, copy this snippet to your .bashrc, reload shell and profit!

command_not_found_handle () {
	if ! ~/.local/share/cmd_not_found.sh "$1" ; then
		echo "$1: command not found"
	fi
	return 127;
}

If you run program that is not installed on your system, it will search for package in oficial repositories and in AUR and show you list of packages that you can install.

#!/bin/bash
query=$1
options=$(packer -Ss "$query" | awk -f <(cat - <<-'EOD'
function ltrim(s) { sub(/^[ \t\r\n]+/, "", s); return s }
/^[^ ]/ {
printf("\"%s\" ", $1);
desc=1;
}
/^ / {
if(desc == 1) {
printf("\"%s\" ", ltrim($0));
desc=0;
}
}
EOD
))
if [ -z "$options" ]; then
exit 1
fi
choice=$(eval "dialog --menu 'Choose a package to install' 22 76 16 $options" 2>&1 >/dev/tty)
clear
if [ ! -z "$choice" ]; then
packer -S "${choice##*/}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment