Package: shfy
ShfyShfy (Shellify) is your best friend when you don't remember how to do something on the command line.It works both as a standalone command line tool and as a shell completion tool.As a standalone command line tool, which should work in almost any shell, it takes a description of what you want to do and returns a command that does it (and an explanation of how it works and if it's safe). See thebasic usagesection for more details.Shfy is most powerful as a shell completion tool. See theshell completionsection for more details.Shfy uses OpenAI's GPT models to generate these suggestions and explanations.Installation or Upgradepip install --upgrade shfyConfigurationThe configuration is read from~/.config/shfy/config.yamlfile. Configuration is optional. See theconfig-example.yamlfile for more details.The configuration file allows you to set the log level, automatic command explanation, model, maximum tokens for each query, and temperature for each query.API KeyOpenAI's API key is required.
The key is read from theOPENAI_API_KEYenvironment variable. If this variable is not set, the API key is read from the~/.config/shfy/api_keyfile.Basic Usage as a standalone command line toolTo use shfy, simply typeshfy <your_prompt>into your terminal. This should work in almost any shell; it has been tested in Bash and Zsh on Linux and Powershell and CMD on Windows.For example, if you wanted to ping your network gateway, you could type:filip@debluna:~$shfyfindmynetworkgatewayandcheckifitisresponding
Suggestion:ping$(iprouteshowdefault|awk'/default/ {print $3}')-c1Executesuggestedcommand?(Y/N)|Explaincommand?(E):y
PING192.168.226.2(192.168.226.2)56(84)bytesofdata.64bytesfrom192.168.226.2:icmp_seq=1ttl=128time=0.342ms

---192.168.226.2pingstatistics---1packetstransmitted,1received,0%packetloss,time0ms
rttmin/avg/max/mdev=0.342/0.342/0.342/0.000ms
filip@debluna:~$By default shfy will not explain the command, but you can ask it to do so by typingewhen prompted. You can also configure it to always explain.(venv)filip@debluna:~$shfyfindmynetworkgatewayandcheckifitisresponding.SayHurray!ifitis,andsomethingisnotrightwhenitisnot
Suggestion:ping-c1$(iprouteshow|awk'/default/ {print $3}')&&echo"Hurray!"||echo"Something is not right"Executesuggestedcommand?(Y/N)|Explaincommand?(E):e
Explanation:Thecommandfindsthenetworkgateway,pingsitonce,andoutputs"Hurray!"ifitresponds,and"Something is not right"ifitdoesnot.Itissafetouse.Taskfulfilled.
Executesuggestedcommand?(Y/N):y
PING192.168.226.2(192.168.226.2)56(84)bytesofdata.64bytesfrom192.168.226.2:icmp_seq=1ttl=128time=0.323ms

---192.168.226.2pingstatistics---1packetstransmitted,1received,0%packetloss,time0ms
rttmin/avg/max/mdev=0.323/0.323/0.323/0.000ms
Hurray!
filip@debluna:~$Shell CompletionShfy works best as a shell completion tool. Currently setup instructions for Bash and Zsh are provided, more can likely be added with relative ease.With shell completion you can gain three new superpowers:Press Ctrl-X Ctrl-G to get a suggested command, based on the current line in the prompt. The existing line will be replaced with the suggested command.Press Ctrl-X Ctrl-F to get an explanation of the current line.Press Ctrl-X Ctrl-H to get a suggested command, based on what is currently in the prompt and the requested changes you enter at the displayed input prompt.BASHAssuming shfy_complete and shfy_explain is in your $PATH. Add the following to your .bashrc or .bash_profile file to gain access to your new superpowers:### START shfy ###shfy_completion(){tputsccurrent_command="$READLINE_LINE"tputel1printf'%s [shfy complete]'"${PS1@P}$current_command"completion=$(shfy_complete"$current_command")tputrcREADLINE_LINE="$completion"READLINE_POINT=${#completion}tputel}bind-x'"\C-x\C-g": shfy_completion'shfy_explanation(){current_command="$READLINE_LINE"tputel1printf'%s [shfy explain]\n'"${PS1@P}$current_command"explanation=$(shfy_explain"$current_command")printf'Explanation: %s\n'"$explanation"}bind-x'"\C-x\C-f": shfy_explanation'read_user_input(){localprompt=$1localinputlocalsaved_stty=$(stty-g)read-ep">$prompt"input</dev/ttystty"$saved_stty"printf"%s""$input"}shfy_changes(){current_command="$READLINE_LINE"tputel1printf'%s [shfy]\n'"${PS1@P}$current_command"user_input=$(read_user_input"Changes: ")printf"[shfy is working...]\n"completion=$(shfy_complete"'$current_command'""changes: '$user_input'")READLINE_LINE="$completion"READLINE_POINT=${#completion}tputel}bind-x'"\C-x\C-h": shfy_changes'### END shfy ###Restart your terminal to access your new superpowers.ZSHAssuming shfy_complete and shfy_explain is in your $PATH. Add the following to your .zshrc file to gain access to your new superpowers:### START shfy ###shfy_completion(){localcurrent_command="$BUFFER"printf" [shfy complete]"localcompletion=$(shfy_complete"$current_command")BUFFER="$completion"CURSOR=${#completion}zlereset-prompt}zle-Nshfy_completion
bindkey'^X^G'shfy_completion

shfy_explanation(){localcurrent_command="$BUFFER"printf" [shfy explain]"localexplanation=$(shfy_explain"$current_command")printf'\nExplanation: %s\n'"$explanation"BUFFER="$current_command"CURSOR=${#current_command}zlereset-prompt}zle-Nshfy_explanation
bindkey'^X^F'shfy_explanation

autoload-Uzread-from-minibuffer

shfy_changes(){localcurrent_command="$BUFFER"printf" [shfy]"read-from-minibuffer'> Changes: 'localuser_input="$REPLY"printf" [shfy is working...]"localcompletion=$(shfy_complete"'$current_command'""changes: '$user_input'")BUFFER="$completion"CURSOR=${#completion}zlereset-prompt}zle-Nshfy_changes
bindkey'^X^H'shfy_changes### END shfy ###