diff --git a/common.sh b/common.sh index 3e48661..8272a90 100644 --- a/common.sh +++ b/common.sh @@ -24,13 +24,6 @@ PERF=$(get_tmux_option "@easymotion-perf" "false") CASE_SENSITIVE=$(get_tmux_option "@easymotion-case-sensitive" "false") SMARTSIGN=$(get_tmux_option "@easymotion-smartsign" "false") -# Create temporary input file with reset character -create_input_file() { - local tmp_file=$(mktemp -t tmux-easymotion_keystroke-XXXXXXX) - printf '\x03' > "$tmp_file" - echo "$tmp_file" -} - # Build environment variables string for neww -d build_env_vars() { local motion_type=$1 diff --git a/easymotion.py b/easymotion.py index 646a4ce..58e7896 100755 --- a/easymotion.py +++ b/easymotion.py @@ -342,14 +342,14 @@ def get_terminal_size(): return width, height - 1 # Subtract 1 from height -def getch(input_file=None, num_chars=1): +def getch(input_str=None, num_chars=1): """Get character(s) from terminal or file Args: - input_file: Optional filename to read from. If None, read from stdin. + input_str: Optional string. If None, read from stdin. num_chars: Number of characters to read (default: 1) """ - if input_file is None: + if input_str is None: # Read from stdin fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) @@ -359,16 +359,7 @@ def getch(input_file=None, num_chars=1): finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) else: - # Read from file - try: - with open(input_file, 'r') as f: - ch = f.read(num_chars) - except FileNotFoundError: - logging.info("File not found") - exit(1) - except Exception as e: - logging.error(f"Error reading from file: {str(e)}") - exit(1) + ch = input_str[:num_chars] if ch == '\x03': logging.info("Operation cancelled by user") exit(1) diff --git a/mode-s.sh b/mode-s.sh index 4a19076..070b74f 100755 --- a/mode-s.sh +++ b/mode-s.sh @@ -6,10 +6,6 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Load common configuration and functions source "$CURRENT_DIR/common.sh" -# Create temporary input file -tmp_file=$(create_input_file) - # Prompt for single character ENV_VARS=$(build_env_vars "s") -tmux command-prompt -1 -p 'easymotion:' "run-shell \"printf %s\\\\n \\\"%1\\\" > $tmp_file\"; \ - neww -d '$ENV_VARS $CURRENT_DIR/easymotion.py $tmp_file'" +tmux command-prompt -1F -p 'easymotion:' "neww -d '$ENV_VARS $CURRENT_DIR/easymotion.py %1" diff --git a/mode-s2.sh b/mode-s2.sh index 2c4f0c3..07cd642 100755 --- a/mode-s2.sh +++ b/mode-s2.sh @@ -6,18 +6,13 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Load common configuration and functions source "$CURRENT_DIR/common.sh" -# Create temporary input file -tmp_file=$(create_input_file) - # Build environment variables ENV_VARS=$(build_env_vars "s2") # First prompt: get first character tmux command-prompt -1 -p 'easymotion char 1:' \ - "run-shell \"printf '%1' > $tmp_file\"; \ - set-option -g @_easymotion_tmp_char1 '%1'" + "set-option -g @_easymotion_tmp_char1 '%1'" # Second prompt: get second character and launch easymotion -tmux command-prompt -1 -p 'easymotion char 2: #{@_easymotion_tmp_char1}' \ - "run-shell \"printf '%1' >> $tmp_file && echo >> $tmp_file\"; \ - neww -d '$ENV_VARS $CURRENT_DIR/easymotion.py $tmp_file'" +tmux command-prompt -1F -p 'easymotion char 2: #{@_easymotion_tmp_char1}' \ + "neww -d '$ENV_VARS $CURRENT_DIR/easymotion.py #{@_easymotion_tmp_char1}%1'"