Skip to content

Commit

Permalink
Get zsh alias working in the current dir, so you can use it while dev…
Browse files Browse the repository at this point in the history
…eloping
  • Loading branch information
dave1010 committed Nov 29, 2023
1 parent 810574b commit 103fc41
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions clipea/clipea.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ if [[ $ZSH_EVAL_CONTEXT != 'toplevel:file' ]]; then
return 1 2>/dev/null || exit 1
fi

DIR="$(dirname -- "$0")"
CLIPEA_TMP_FILE=$(mktemp)

TMP_FILE=$(mktemp)
# https://stackoverflow.com/questions/9901210/bash-source0-equivalent-in-zsh
CLIPEA_SCRIPT_DIR=$(dirname $(readlink -f ${(%):-%x}))

# Execute the PHP script with an environment variable
CLIPEA_CMD_OUTPUT_FILE="$TMP_FILE" "$(which clipea)" "$@"
CLIPEA_PYTHON=

CLIPEA_PATH=$(which clipea)

# Run clipea from the current dir if possible
if [[ -f $CLIPEA_SCRIPT_DIR/__main__.py ]]; then
CLIPEA_PATH=$CLIPEA_SCRIPT_DIR
CLIPEA_PYTHON="$(which python3 || which python)"
fi

# Execute clipea with an environment variable
CLIPEA_CMD_OUTPUT_FILE="$CLIPEA_TMP_FILE" $CLIPEA_PYTHON "$CLIPEA_PATH" "$@"

# Read the command to be placed on the Zsh command line
commandToPlace=$(< "$TMP_FILE")
CLIPEA_COMMAND_TO_PLACE=$(< "$CLIPEA_TMP_FILE")

# Place it on the Zsh command line
print -rz "$commandToPlace"
print -rz "$CLIPEA_COMMAND_TO_PLACE"

# Remove the temp file
rm "$TMP_FILE"
rm "$CLIPEA_TMP_FILE"

0 comments on commit 103fc41

Please sign in to comment.