-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromf
More file actions
39 lines (37 loc) · 1.41 KB
/
promf
File metadata and controls
39 lines (37 loc) · 1.41 KB
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
33
34
35
36
37
38
39
# $ZDOTDIR/.zfunc/promf
#Prompt manipulation function for Zshelf. Works on file $TPROMPTF.
#`promf filename` append a file OR
#`promf 'Some text'` append some text OR
#`promf` append PRIMARY selection OR
#`promf l` list dir contents OR
#`promf c` list $TPROMPTF contents OR
#`promf e` edit $TPROMPTF file (for those who do not use the link in $RPROMPT)
#`promf x` delete $TPROMPTF (single char x != 'l','c' or 'e')
#promf () {
#Adjust the next variables for your case:
local size_limit=175000 # 175kB in bytes, average file size for 131072 tokens.
#Replace `ne` in next statement with your favorite command-line editor.
local editor=${EDITOR:-ne}
(( ${+TPROMPTF} )) || source $ZDOTDIR/.zfunc/qlm.cfg
if (( $# )); then
if [[ -f $1 ]]; then
cat "$1" >> $TPROMPTF
elif (( $#1 - 1 )); then
echo -e "$1" >> $TPROMPTF
else
[[ $1 == "l" ]] && { ls -al "${TPROMPTF:h}" ; return 0 ; }
[[ $1 == "c" ]] && { cat $TPROMPTF ; return 0 ; }
[[ $1 == "e" ]] && { command $editor $TPROMPTF ; return 0 ; }
rm $TPROMPTF
fi
else
echo -e "$(xsel -op)\n" >> $TPROMPTF
fi
if [[ -f $TPROMPTF ]]; then
local file_size=$(stat -c%s "$TPROMPTF")
if (( file_size > size_limit )); then
echo "WARNING: Please, check that $TPROMPTF does not exceed the maximum context window of your model!"
fi
fi
return 0
#}