Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverisaac committed Jan 17, 2022
0 parents commit b0a3d61
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# iTerm Command

This repo has a tool which does two things:

1. Handle clicks from iterm
2. Generate files which the iterm click-handler can understand
33 changes: 33 additions & 0 deletions handle-click
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -euo pipefail

EDITOR="${EDITOR:-vim}"

function handle_click(){
file="$1"
line_number="${2:-}"

itermRegex='^/tmp/iterm2-cmd/([a-f0-9A-F]+)$'
if [[ "$file" =~ $itermRegex ]]; then
cat "$file"
echo
elif [[ -f "$file" ]]; then
args=( "${EDITOR}" )

# Set the line number
if [[ -n "$line_nubmer" ]]; then
if [[ ${EDITOR} == vim ]] || [[ $EDITOR == vi ]]; then
args=( +${line_number} )
elif [[ ${EDITOR} == code ]]; then # visual studio code
args=( -g "$file:${line_number}" )
fi
fi
printf "%q " "${args[@]}"
echo
else
printf 'echo "< $PWD ^ $( dirname %q )"; cd %q; ls;\n' "$file" "$file"
fi
}

handle_click "${@}"

0 comments on commit b0a3d61

Please sign in to comment.