cf
CLI a lot. As you perhaps may know already, due to the use of Multi Target Applications (multiapps, or MTAs) in the SAP Cloud Platform CF environment, there's a plugin system for cf
- with the most popular plugin for us being the multiapps plugin for managing MTAs.cf
at any particular point). I use the commands provided by this plugin (targets
, save-target
, delete-target
and set-target
) often, but I also like choosing my target from a list, so I can see what I'm connected to currently, and what I want to switch to.cf targets
and then select a new target with cf set-target
:fzf
takes whatever it's given via STDIN, and presents it in a selection. You can then use various methods to narrow down your search through the selection and choose something, at which point fzf
will then simply output that selection to STDOUT. This is a classic example of the Unix philosophy of tools doing one thing and doing it well, and also conforming to the simple but powerful concepts of pipelining and standard input & output.fzf
to enhance the flow above, so that I'm simply presented with a list of targets for me to choose from. I wrote a very short script, that looks like this:#!/usr/bin/env bash
target=$(cf targets | fzf --height=25% | cut -d ' ' -f 1) \
&& [ ! -z ${target} ] \
&& cf set-target -f ${target} \
&& cf target
target=$(cf targets | fzf --height=25% | cut -d ' ' -f 1) \
cf targets
, which will produce that list of targets available, including highlighting the currently selected target with "(current)" as we saw earlier. It then pipes that into fzf
, which will present me with those options in a short (25% of the height of the current terminal) list to choose from, using fuzzy searching or simply using the up and down arrow keys.cut
is used to take just the first word from the line selected (this is important in the case where "(current)" is added to the line) and then the result is saved into the target
variable. && [ ! -z ${target} ] \
&& cf set-target -f ${target} \
cf set-target
command to set the API endpoint to the appropriately selected target.cf target
command (not to be confused with cf targets
😞 && cf target
cft
(for 'cf target') and now I can view and select CF targets in comfort!cft
in action, where the current target is 'workflowcodejam' and I want to switch to 'garage':You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
14 | |
7 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 |