Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-UTF-8 characters segfault #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions fmenu-rofi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ OPTIONS:
-f force reloading index [default: false]
-t time [default: 5min]
-u Just update the index
-n Prevent it from building the index
EOF
}

Expand All @@ -26,7 +27,9 @@ TIME="+5"
INPUT=$HOME
EXCLUDE='.*/\..*'
DRY=false
while getopts "ht:fd:o:i:x:u" OPTION
BUILD_INDEX=true
SHIFT=0
while getopts "ht:fd:o:i:x:un" OPTION
do
case $OPTION in
h)
Expand All @@ -35,48 +38,68 @@ do
;;
f)
FORCE=true
SHIFT=$((SHIFT + 1))
;;
d)
DMENU=$OPTARG
SHIFT=$((SHIFT + 2))
;;
t)
TIME=$OPTARG
SHIFT=$((SHIFT + 2))
;;
o)
INDEX=$OPTARG
SHIFT=$((SHIFT + 2))
;;
i)
INPUT=$OPTARG
SHIFT=$((SHIFT + 2))
;;
x)
EXCLUDE=$OPTARG
SHIFT=$((SHIFT + 2))
;;
u)
FORCE=true
DRY=true
SHIFT=$((SHIFT + 1))
;;
n)
BUILD_INDEX=false
SHIFT=$((SHIFT + 1))
;;
?)
usage
exit
;;
esac
shift 1
done

shift $SHIFT

function index_files {
find "$INPUT" \( ! -regex "$EXCLUDE" \) | sed 's/ /\\ /g' | sort -f > "$INDEX"
find "$INPUT" \( ! -regex "$EXCLUDE" \) | sed 's/ /\\ /g' | sort -f > "$INDEX.raw"
iconv -f utf-8 -t utf-8 -c "$INDEX.raw" -o "$INDEX"
rm "$INDEX.raw"
}

if [[ ! -a "$INDEX" ]] || ( test `find $INDEX -mmin $TIME` ) || ($FORCE)
if ( $BUILD_INDEX )
then
index_files
if [[ ! -a "$INDEX" ]] || ( test `find $INDEX -mmin $TIME` ) || ($FORCE)
then
index_files
fi
fi

if ( ! $DRY )
then
if [ -z $@ ]
then
cat "$INDEX"
if [[ -a "$INDEX" ]]
then
cat "$INDEX"
fi
else
xdg-open $@ > /dev/null &
fi
Expand Down