-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b0a3d61
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |
This file contains 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
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 "${@}" |