-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcontext.zsh
32 lines (26 loc) · 1.09 KB
/
context.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/zsh
CONTEXT_FILE=$(find "${SCRIPT_DIR}/.tmp/" -name ".context_${pid}_??????" | head -n 1)
# Determine the current operating system for platform-specific handling
OS=$(uname)
# Update the context file
update_context() {
local his=$(history | grep -v '^[[:space:]]*[0-9]\+\*' | tail -16)
print -r "$BUFFER" > $CONTEXT_FILE
pwd >> $CONTEXT_FILE
print -r "$his" >> $CONTEXT_FILE
ls -p >> $CONTEXT_FILE
}
# Update the context file with current line buffer
update_context_buffer() {
if [[ "$OS" == "Darwin" ]]; then
sed -i '' "1s|.*|$(_zsh_autosuggest_escape_command "${BUFFER:-}")|" "$CONTEXT_FILE"
#sed -i '' "1s/.*/$(printf "%s" "${BUFFER:-}" | sed 's/[\/&]/\\&/g')/" "$CONTEXT_FILE"
else
sed -i "1s|.*|$(_zsh_autosuggest_escape_command "${BUFFER:-}")|" "$CONTEXT_FILE"
#sed -i "1s/.*/$(printf "%s" "${BUFFER:-}" | sed 's/[\/&]/\\&/g')/" "$CONTEXT_FILE"
fi
}
# Set up hooks to update suggestions as you type
autoload -U add-zle-hook-widget
add-zle-hook-widget line-init update_context
add-zle-hook-widget zle-line-pre-redraw update_context_buffer