reXply is a handy tool to copy/paste replies and scripts with an advanced front-matter system for variables substitutions and dynamic per-template settings, bash script processing/evaluation, and much more, that can also be used as a launcher to other scripts/executables!
v0.1.6 - View changelog
dmenu
and/oryad
xclip
and/orxsel
and/orpbcopy
+pbpaste
xdotool
(optional but strongly recommended)
More info regarding these dependencies at the end of this file.
- install as more dependencies as you can on your system (recommended:
dmenu
,yad
,xclip
,xdotool
) - clone this repo
- symlink the binary in a folder in your $PATH
If you are unsure, just copy and paste on your terminal (the script will try to install the dependencies - if you're using Linux):
cd ~/ && \
git clone https://github.com/renatofrota/rexply.git && \
rexplylink=$(echo $PATH|cut -d: -f1)/rexply && \
{ [ ! -f $rexplylink ] && sudo ln -s ~/rexply/rexply.bash $rexplylink ; }; \
[ ! -f $(echo $PATH|cut -d: -f1)/rexply ] && echo problem creating symlink || \
echo "all done! now assign a keybinding to call 'rexply' on your O.S. ;)"
- download and extract the zip or clone the repo to an alternative location
- copy everything over your existing install (except rexply.cfg)
If you are unsure, just copy and paste on your terminal:
OLD_IFS=$IFS && IFS=$'\n' && cd ~/ && echo -n "Downloading..." && \
wget -q -O rexply.zip https://github.com/renatofrota/rexply/archive/master.zip && \
echo -en "\nExtracting..." && sleep 1 && unzip -q -o rexply.zip && mkdir -p rexply && \
echo -en "\nCopying over..." && sleep 1 && for dir in $(find rexply-master/ -type d); \
do mkdir -p "$(echo $dir | sed 's,^rexply-master,rexply,')"; done && \
for file in $(find rexply-master -type f ! -name rexply.cfg); \
do cp "$file" "$(echo $file | sed 's,^rexply-master,rexply,')"; done && \
echo && read -rep "Reinstall rexply.cfg file? [y/n]: " -n 1 reinstall && \
{ if [[ "$reinstall" =~ (1|y|Y|s|S) ]]; then cp rexply-master/rexply.cfg rexply/; fi ; } && \
rm -rf rexply-master rexply.zip && echo "All done!" && IFS=$OLD_IFS
It works from command line (terminal) - just type in 'rexply'.
But it is only 1% as useful as it could be by running it this way. To feel the power:
- add the custom command
rexply
to your Keyboard shortcuts/keybindings area; - bind a key to the custom command you've created
- go to an editor, browser, or any other text area field
- press the binded key and be amazed!
The default replies/scripts repository is $HOME/rexply/rexply-data/repository
.
You can just create more folders/files there (or change default repository in rexply.cfg).
The files can be:
- regular text files
- text with dynamic questions
- front-matter powered templates
- "evaluated" (processed with
eval
) - bash scripts (executable scripts - preferably with
#!/bin/bash
hashbang) - or any other binary/executable script/application (after enabling
$execute
)
No secrets on this. I just recommend you append .txt to the file names so your editors do not try to apply syntax highlighting based on file contents.
You can add questions that will be dynamically replaced during text processing.
Hello, {{?Friend's name?}}! How are you going today?
When pasting this template, you will be asked "Friend's name?" (the last ?
is not part of dynamic questions syntax, it's part of the question itself).
Create a section with some variables at the top of the file (surround the variables by ---
above and below) and use them within template text in format ${varname}
. Example:
---
#vartype:varname!Field Label:default value
#field label and default value are optional
entry:customer!Customer name:
txt:code!Code used to fix
num:minutes!Time to take effect (in minutes):10!0..20!5
---
Hello ${customer},
Thanks for getting in touch with us.
To resolve this problem I've added this code to [b]public_html/.htaccess[/b] file on your account:
[code]${code}[/code]
This change should reflect in aproximately ${minutes} minutes.
@
When inserting this template, reXply will ask you to provide the data to the 3 variables:
- your customer's name
- the code you've used to resolve his problem
- how many minutes it will take to reflect on his end
After the variable name, you can add :
and the default input for that variable. When no default is provided, variable name will be the default. To make default empty just add :
and nothing else in front of it.
If using dmenu
, you will see an empty field with a 'selection' below (the default input). You can type any value or just hit enter to use the pre-selected option. One field at a time. Optionally, a preview of all the fields can be displayed underneath the selector ($preview='1'
).
If using yad
, a form will be displayed, with all fields visible and editable simultaneously. Each field is pre-filled with the default value data (or the variable name, if you have set no default value). Numeric fields will have +/- buttons - and may be limited to the range you have defined. In the example above !0..20!5
means "a value between 0 to 20, in steps of 5". The "steps" are only for the +/- buttons (or up/down arrows): any value within the allowed range can be manually entered.
Oh, and the @ at the end is to confirm you want the 2 blank lines processed (any @
at the very end of the template is removed during processing - if $checkpt
is enabled, or -k 1
is passed). Without it, the 2 lines would be discarded.
The syntax for a front-matter variable is vartype:varname[!var label][:][default value]
, where:
vartype
- variable type (see types below) - mandatoryvarname
- the name of the variable (used to perform the substitutions in template file) - mandatoryvar label
- the label that is displayed in Dmenu/Yad forms that fieldthe colon sign
- to indicate a default value followsdefault value
- the default value for the variable
The last 3 are optional.
Currently, 5 types of data variables are supported
entry
,field
,var
ortext
- single line input fieldtxt
ortextarea
- multiline (textarea) input fieldnum
ornumeric
- a field that only allow numbers [ with a default value [ a defined range of accepted values [ and a default stepping ] ] ] (num:varname[:default[!MIN..MAX[!STEP]]]
)- a default is specified as usual:
num:minutes:10
- an accepted range is specific by appending
!MIN..MAX
(e.g.:num:minutes:10!0..20
) - the stepping comes after, also separated by
!
(e.g.:num:minutes:10!0..20!5
) - note: the acceptance of these settings depends on the application you use to process front-matter vars (
$yadform
or-Y
parameter)- yad
- accepts all parameters
- the visual +/- buttons and up/down keyboard arrows respect the range and stepping
- you can still manually type a value out of the range and/or disrespecting the stepping
- dmenu
- takes the default value
- discard all the rest
- yad
- a default is specified as usual:
select
orselectbox
- a field with a list of pre-defined values displayed as a selectbox itemcombo
orcombobox
- like select field, but allows a custom value to be entered
You may want to display a ${variable}
in it's literal form (when it's part of the final command you want to run after template is processed). There are 2 ways to do this:
- add an entry variable and set the default value to the variable string:
entry:variable:${variable}
- it will be displayed during front-matter processing - and you can override it (as any
entry
var)
- it will be displayed during front-matter processing - and you can override it (as any
- use the special front-matter command
keep
:keep:variable
- it won't be displayed during front-matter processing
Note: variables in format $variable
(without {}
) are parsed as environment variables (they will "disappear" when pasting a template if they do not exist on your environment). Always use ${variable}
format (with {}
).
3 special front-matter variables can be used to override reXply options. Note: they must come before regular variables.
They accept 0
/1
, like the config vars themselves, aliases like true
/false
, yes
/no
, and some others (check rexply.bash code if you're curious).
yadform
oreditor
(overrides$yadform
)preview
(accepts0
,1
,2
)runeval
- dmenu:
- Enter submit selection or input.
- Shift+enter to submit input.
- Ctrl+y to paste primary X selection ("mouse highlight")
- Ctrl+Y to paste clipboard
- yad:
- Regular shortcuts (enter submit, tab change field)
- On multiline textareas, ctrl+tab to change field
- You cannot use
|
in provided data as it will break the field<->data association
---
field:var_name:default value#this is a comment (variable is processed)
#this line is also a comment. this method or above are valid and recommended
this line is not a comment but parsing will fail: 'this' is not a valid variable type
---
- you can type
\\n
while filling in front-matter variables data - reXply will convert these to line breaks when pasting the data to your application. - the preview lines (those displayed below
dmenu
when$yadform='0'
(-Y 0
), while processing a file with front-matter variables) are "filtered" as you type - and will eventually disappear: as soon as your data input do not match any of them. If it is a problem for you (you ends up selecting an existing item when trying to insert a data with shorter lenght to the next fields) you can resolve by one of the methods below ("it's simple, I will disable preview in config", you may think at first - yes, it works, but there are several smarter ways to "fix" it without taking it hard):- use shift+return to submit to send your current input instead selected item
- disable preview specifically for that template, by adding
preview:false
to it's front-matter; - change the order of variables in the front-matter (place variables that expects a shorter input at the top);
You can add bash subshells $()
on your file. These will be executed (with your homedir as their initial working directory) and their output will replace the subshell dynamically in the template (just like as any command you run in a terminal window).
Environment variables like ${USER}
, ${PWD}
, etc are also replaced even when outside $()
Note: some consider eval dangerous (have you ever heard eval is evil?) so environment vars and front-matter vars substitutions are made using just envsubst
by default - if you want to go evil way, I mean.. eval way, enable eval by setting $runeval='1'
, passing -E 1
parameter, or add runeval:true
to template front-matter).
They are executed when selected in the menu and you have execution permissions over the file (chmod +x path/to/filename.bash
).
Be careful. Your homedir is the initial working directory when you start reXply using a keybinding. When running from command line, the working dir is kept.
Please note:
- if the file is not executable, no matter the extension, it will be processed as a regular text template.
- the files are not executed directly by default (
$execute='0'
), they are called throughbash
, like this:bash <file>
. - If you enable
$execute
or pass-X 1
the file will be executed direcly, making reXply act as a truly and independent "launcher" for your applications/scripts.
I recommend you add #!/bin/bash
hashbang at the top of the file and use .bash
or .sh
extension so your text editors also know they are shell executable files - and they keep being properly executed if you enable $execute
.
reXply will, by default:
- hide directories and files preceded by a dot (e..g:
.filename
) -$showall='0'
- disallow browsing to parent directories outside it's default repository -
$breakit='0'
- hide form list any file bigger than a pre-defined size limit (default: 3MB) -
$maxsize='3'
- prevent execution of arbitrary executables (call executables using
bash $filename
) -$bashit='1'
All these restrictions are due to security concerns and can be modified by either:
- modifying the rexply file directly (
$HOME/rexply/rexply.bash
); or - modifying the additional config file (
$HOME/rexply/rexply.cfg
)
We will avoid updating the additional config file but take your backups before updating, please.
- test if everything works in OSX (help wanted)
- improve textarea fields (the pipe char
|
currently breaks field<->data associations) - provide a way to create new files with front-matter headers using the script itself
- buy more coffee (please donate below!)
dmenu
is the standard application used to output information and capture input due to it's more widespread presence - including availability on OSX via Homebrew, etc. If you want more fancy visual, with screen-centered dialogs, ability to fill in all front-matter variables of a template in a single - floating window - form, set options$yadfile
(file selection) and$yadform
(front-matter form) to1
(or runrexply -y 1 -Y 1
) so you can useyad
instead.xclip
may be substituted withxsel
(see$copycmd
option) orpbcopy
andpbpaste
- useful in OSX, I just had no time to test yet, so it may need some polishing.xdotool
is used to handle the window focus (and apparently, it's not that easy to make it work on OSX due toXTEST
not being active by default). You can get rid of this dependency by disabling$focusit
option. A possible problem if you are using the script to paste data (withxclip
orxsel
) while another window is set as 'always-on-top': the data will sometimes end up being pasted to the window set as 'always-on-top' instead the desired window (depends on the application and other circumstances - not tested on OSX yet).
xdotool
is used to paste in Linux by default. In OSX, the default is no automatic pasting and using pbcopy/pbpaste instead ($pasteit='0'
and $copycmd='3'
). The processed data should be on your clipboard, just paste it manually after running reXply.
If you want to try automatic pasting, there are 2 ways to implement it:
- set
$pastedefault='eval cat $1'
and$pasteterminal='eval cat $1'
(or just pass-P 'eval cat $1'
parameter) - note the single quotes - and pipe reXply to whichever program you want to use to handle the data in sequence. Just as an example, at least theoretically, piping the output topbcopy
(e.g.:rexply -P 'eval cat $1' | pbcopy
) the data will be copied to clipboard (as reXply does by default) and you can paste it manually. I could not test (pbcopy not available in my Linux distro andxclip
/xsel
handles input buffer a bit differently). Feel free to try this and other ways to parse the output :) - there's another option: disable automatic pasting with
$pasteit='0'
(what is default for OSX) and also set it to keep the tmpfile after processed ($deltemp='0'
or-d 0
), then use the processed data saved at tmpfile (by default,$HOME/rexply/rexply-data/.tmp/tmp
) by your own way.
Help me keep my stuff Open Source and free.
Think on how much time($) you're saving with this tool and buy me some coffee! :)
USD
BRL