Skip to content

Instantly share code, notes, and snippets.

@polymorphm
Created November 28, 2011 20:56
Show Gist options
  • Save polymorphm/1402011 to your computer and use it in GitHub Desktop.
Save polymorphm/1402011 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# -*- mode: bash; coding: utf-8 -*-
cool_hack_encoding="WINDOWS-1251"
if [ -z "$1" ]
then
echo "missing file path" >&2
exit 2
fi
file_path=$1
shift
if [ ! -f "$file_path" ]
then
echo "file not exists" >&2
exit 2
fi
if iconv "$file_path" >/dev/null 2>&1
then
# file is normal! all good :-)
exec gedit "$file_path" "$@"
else
# file is damaged or it is COOL HACKERS!!! :D
exec gedit --encoding="$cool_hack_encoding" "$file_path" "$@"
fi
false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment