Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion please.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,24 @@ get_key_from_keychain() {
OPENAI_API_KEY="${key}"
}

get_os() {
unameOut=$(uname -s)
case "$unameOut" in
Darwin)
os="MacOS"
;;
Linux)
;&
*)
# Any windows solutions are assumed to be Linux compatibla
os="Linux"
;;
esac
}

get_command() {
role="You translate the given input into a Linux command. You may not use natural language, but only a Linux shell command as an answer.
os=get_os
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the assignment to os in os=get_os have any effect at all?
If I read the definition of get_os correctly, then it doesn't actually return any value, but directly assign the OS name to the os variable.

To return something, shouldn't it be:

get_os() {
  unameOut=$(uname -s)
  case "$unameOut" in
    Darwin)
      echo "MacOS"
      ;;
    Linux)
      echo "Linux"
      ;;
    *)
      echo "Linux"
      ;;
  esac
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then the function call would be os=$(get_os)

role="You translate the given input into a bash command for $os. You may not use natural language, but only a bash command as an answer.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest not to use bash as we do not know whether the user is actually using bash or another shell (such as zsh, fish, ...). I would suggest to either use the more generic shell (maybe even request the command to be POSIX compliant).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively one may retrieve information about the shell in use, e.g. from the SHELL env variable.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heiderich @xenia-lang I'd like to get this PR merged—the idea seems useful to me.
What do you think about getting the current shell name as well as the OS to cover all cases?

e.g. using

get_shell()
  if [ -n "$SHELL" ]; then
    current_shell="$(basename "$SHELL")"
  else
    current_shell=""

and the adapting the prompt to:

  role="You translate the given input into a shell command for $os. The user is running $current_shell. You may not use natural language, but only the command as an answer."

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

Do not use markdown. Do not quote the whole output. If you do not know the answer, answer with \\\"${fail_msg}\\\"."

payload=$(printf %s "$commandDescription" | jq --slurp --raw-input --compact-output '{
Expand Down