Last active
November 22, 2024 10:23
-
-
Save a5r0n/e45f2c1079f20ef64864645f27918efc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Hebrew to English keyboard mapping | |
| declare -A HEB_TO_ENG | |
| HEB_TO_ENG=( | |
| ['ש']='a' ['נ']='b' ['ב']='c' ['ג']='d' ['ק']='e' | |
| ['כ']='f' ['ע']='g' ['י']='h' ['ן']='i' ['ח']='j' | |
| ['ל']='k' ['ך']='l' ['צ']='m' ['מ']='n' ['ם']='o' | |
| ['פ']='p' ['/']='q' ['ר']='r' ['ד']='s' ['א']='t' | |
| ['ו']='u' ['ה']='v' ['׳']='w' ['ס']='x' ['ט']='y' | |
| ['ז']='z' | |
| ) | |
| # Function to convert Hebrew text to English | |
| hebrew_to_english() { | |
| local input=$1 | |
| local output="" | |
| # Convert each character | |
| for (( i=0; i<${#input}; i++ )); do | |
| local char="${input:$i:1}" | |
| if [[ -n "${HEB_TO_ENG[$char]}" ]]; then | |
| output+="${HEB_TO_ENG[$char]}" | |
| else | |
| output+="$char" | |
| fi | |
| done | |
| echo "$output" | |
| } | |
| # Store the original handler | |
| if ! typeset -f original_command_not_found_handler > /dev/null; then | |
| if typeset -f command_not_found_handler > /dev/null; then | |
| eval "original_command_not_found_handler() { | |
| $(typeset -f command_not_found_handler | grep -v '^command_not_found_handler.*$') | |
| }" | |
| else | |
| original_command_not_found_handler() { | |
| echo "zsh: command not found: $1" >&2 | |
| return 127 | |
| } | |
| fi | |
| fi | |
| # New command not found handler that chains to the original | |
| command_not_found_handler() { | |
| local cmd=$1 | |
| # First, check if command contains Hebrew characters | |
| if [[ $cmd =~ [קראטוןםפשדגכעיחלךצמנהבסזת] ]]; then | |
| local converted=$(hebrew_to_english "$cmd") | |
| # Check if the converted command exists | |
| if command -v "$converted" >/dev/null 2>&1; then | |
| echo -e "\nנראה שהקלדת את הפקודה בעברית בטעות." | |
| echo -e "האם התכוונת להריץ: $converted?\n" | |
| # Ask for confirmation | |
| echo -n "הקש y לאישור: " | |
| read -k 1 answer | |
| echo "" | |
| if [[ $answer == "y" ]]; then | |
| echo "מריץ: $converted" | |
| eval "$converted ${@:2}" | |
| return $? | |
| fi | |
| fi | |
| fi | |
| # If not Hebrew or user declined, pass to original handler | |
| original_command_not_found_handler "$@" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment