Skip to content

Instantly share code, notes, and snippets.

@Nyubis
Created August 9, 2017 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nyubis/96e6da3ad52c20ad4524f64116b5267d to your computer and use it in GitHub Desktop.
Save Nyubis/96e6da3ad52c20ad4524f64116b5267d to your computer and use it in GitHub Desktop.
fullwidth shell script
#!/bin/bash
# script for converting text to fullwidth characters on the clipboard
# don't try to enter anything that doesn't have a fullwidth equivalent
# usage: fw test
# result: the clipboard now contains test
words=$*
for (( i=0; i<${#words}; i++ )); do
char="${words:$i:1}"
if [[ "${char}" == " " ]]; then
# for some reason, the ideographic space is not in the fullwidth block
# the mysteries of unicode, I suppose.
printf " "
else
# handle characters that aren't spaces, transforming them
# into their fullwidth equivalent (hope they have it)
codepoint=$(printf '%x' "'$char")
fwcp=$(printf '\\uFF%02x' $((0x$codepoint - 0x20)))
printf $fwcp
fi
done | xsel -ib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment