#!/usr/bin/env python3 """ Script Name: u+ Description: Unicode character lookup by hex code Source: https://evanhahn.com/scripts-i-wrote-that-i-use-all-the-time/ Credit: Evan Hahn - https://codeberg.org/EvanHahn/dotfiles Usage: u+ 1F4A9 # 💩 PILE OF POO u+ 2665 # ♥ BLACK HEART SUIT u+ 0041 # A LATIN CAPITAL LETTER A """ import argparse import sys import unicodedata def main(): parser = argparse.ArgumentParser(description='Look up Unicode character by hex code') parser.add_argument('hex_code', help='Hexadecimal Unicode code point (e.g., 1F600)') args = parser.parse_args() try: # Convert hex to int code_point = int(args.hex_code, 16) # Get character and name char = chr(code_point) try: name = unicodedata.name(char) except ValueError: name = "" # Output: character and name print(f"{char} U+{args.hex_code.upper()} {name}") except ValueError: print(f"Error: Invalid hex code '{args.hex_code}'", file=sys.stderr) sys.exit(1) except Exception as e: print(f"Error: {e}", file=sys.stderr) sys.exit(1) if __name__ == '__main__': main()