Skip to content

Instantly share code, notes, and snippets.

@hitswa
Created March 7, 2015 06:46
Show Gist options
  • Save hitswa/59239d6b1ab3306868ae to your computer and use it in GitHub Desktop.
Save hitswa/59239d6b1ab3306868ae to your computer and use it in GitHub Desktop.
Everything Search Engine alternative script for ubuntu
#!/bin/bash
t=$(mktemp)
locate "$1" | awk '{ printf "%4d\t\"%s\"\n", NR, $0 }' > $t
[[ -s $t ]] || { echo "No results found"; exit; }
rows=$(wc -l "$t" | cut -d' ' -f1)
if [[ $rows == 1 ]]; then
file=$(sed 's/^.*\t"\(.*\)"$/\1/' $t)
xdg-open "$file" &
else
response=$(dialog --stdout --menu 'Choose a File:' 20 70 15 --file $t)
if [[ -n "$response" ]]; then
file=$(sed -n "/^\s*$response\t/{s/^.*\t\"\(.*\)\"$/\1/;p}" $t)
if [[ -n $file ]]; then
echo "You chose $file"
xdg-open "$file" &
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment