Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 4 additions & 13 deletions easymotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions mode-s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 3 additions & 8 deletions mode-s2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Loading