Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # The script replaces some keyboard characters and their combinations
- # with typographically correct ones, for example hyphens padded with
- # spaces are converted to em- or en-dashes. Works with both English
- # and Russian text. The text for conversion should be placed in the
- # clipboard; the converted text is returned by the script to the
- # clipboard too. espeak, xclip and yad need to be installed for the
- # script to work, otherwise they should be replaced with alternatives;
- # espeak is only used for verbal notification so it can be removed
- # from the code if such notification is not needed.
- function quitting()
- {
- espeak -v english "$1"
- exit "$2"
- }
- function cyrillic()
- {
- echo -n "$input" | sed -r 's/(^| )([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)([A-Za-zА-Яа-я0-9])/\1\2«\3«\4\5/g; s/([A-Za-zА-Яа-я0-9])([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)( |$)/\1\2»\3»\4\5/g; s/(^| )([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)([A-Za-zА-Яа-я0-9])/\1\2«\3\4/g; s/([A-Za-zА-Яа-я0-9])([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)( |$)/\1\2»\3\4/g; s/^([^«»]*)«([^«»]*)«/\1„\2«/g; s/»([^«»]*)»([^«»]*)$/»\1“\2/g; s/^-+ /— /g; s/ -+ / — /g; s/\.\.\./…/g; s/([0-9]) *-+ *([0-9])/\1—\2/g' | xclip -i -selection clipboard
- }
- function latin()
- {
- echo -n "$input" | sed -r 's/(^| )([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)([A-Za-zА-Яа-я0-9])/\1\2“\3“\4\5/g; s/([A-Za-zА-Яа-я0-9])([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)( |$)/\1\2”\3”\4\5/g; s/(^| )([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)([A-Za-zА-Яа-я0-9])/\1\2“\3\4/g; s/([A-Za-zА-Яа-я0-9])([^ A-Za-zА-Яа-я0-9]*)"([^ A-Za-zА-Яа-я0-9]*)( |$)/\1\2”\3\4/g; s/^([^“”]*)“([^“”]*)“/\1‘\2“/g; s/”([^“”]*)”([^“”]*)$/”\1’\2/g; s/^-+ /– /g; s/ -+ / – /g; s/\.\.\./…/g; s/([0-9]) *-+ *([0-9])/\1–\2/g' | xclip -i -selection clipboard
- }
- input=$(xclip -o -selection clipboard)
- if [[ $input =~ ^.*[A-Za-z].*[А-Яа-я].*$ ]] || [[ $input =~ ^.*[А-Яа-я].*[A-Za-z].*$ ]]; then
- yad --title="Typograph" --text="Select a character set: " --button='Cyrillic:0' --button='Latin:1' --button="Abort:2" --borders=8
- case "$?" in
- 0)
- cyrillic
- ;;
- 1)
- latin
- ;;
- 2)
- quitting "Aborted!" 1
- ;;
- *)
- true
- ;;
- esac
- else
- if [[ $input =~ ^.*[А-Яа-я].*$ ]]; then
- cyrillic
- else
- latin
- fi
- fi
- quitting "Done!" 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement