hotshell
hotshell copied to clipboard
Temporary edit a command
Sometimes I'd like to edit a command in my menu before running it.
Some cases where it could happen.
- Replace a hostname by an IP address (because hostname cannot be resolved)
- Edit a parameter in the predefined command (
ssh user@hostname watch -n5 nvidia-smi
->ssh user@hostname watch -n1 nvidia-smi
- etc.
Proposal
Add a combination key (Alt+
Thanks for submitting this issue.
This is definitely a useful feature to have.
Two ideas that come to my mind to implement it, either
- enter "bash" mode and pre-populate it with the selected command
- integrate a readline library such as chzyer/readline or sahib/readline
In the meantime, here are workarounds that I often use :
Edit a parameter in the predefined command (ssh user@hostname watch -n5 nvidia-smi -> ssh user@hostname watch -n1 nvidia-smi
A script can be used to take the watch interval as a parameter or prompt for a value if not provided :
#./watch-nvidia-smi.sh
INTERVAL=$1
if [ -z "${INTERVAL}" ]; then
echo -n "Watch interval: "; read INTERVAL
fi
ssh user@hostname watch -n$INTERVAL nvidia-smi
The script can then be used several ways :
item({key: 'p', desc: 'prompt for interval', cmd: './watch-nvidia-smi.sh'})
item({key: '1', desc: 'interval = 1', cmd: './watch-nvidia-smi.sh 1'})
item({key: '2', desc: 'interval = 2', cmd: './watch-nvidia-smi.sh 2'})
Instead of prompting for a value, a default one can be hard-coded :
#./watch-nvidia-smi-wo-prompt.sh
ssh user@hostname watch -n${1:-5} nvidia-smi
item({key: 'd', desc: 'default interval (=5)', cmd: './watch-nvidia-smi-wo-prompt.sh'})
item({key: '1', desc: 'interval = 1', cmd: './watch-nvidia-smi-wo-prompt.sh 1'})
item({key: '2', desc: 'interval = 2', cmd: './watch-nvidia-smi-wo-prompt.sh 2'})
Replace a hostname by an IP address (because hostname cannot be resolved)
This one depends on your actual use case.
Are you trying to connect to a SSH server where its hostname and ip address rotates amongst a known set of values? In that case, here is a script that tries to connect to a set of addresses in turn until it succeeds :
#ssh-with-fallback.sh
addrs=(unknown-hostname 127.0.0.1 localhost)
for addr in "${addrs[@]}"
do
if ssh $addr; then
break
fi
done