diff --git a/package-lock.json b/package-lock.json index ad63c87..2c0481e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@abhagsain/ai-cli", - "version": "1.0.1-0", + "version": "1.1.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@abhagsain/ai-cli", - "version": "1.0.1-0", + "version": "1.1.2", "license": "AGPL-3.0-or-later", "dependencies": { "@oclif/core": "^1.19.1", diff --git a/src/helpers/index.ts b/src/helpers/index.ts index 9c7ea72..ad47ffa 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -18,5 +18,21 @@ export const getOpenAIKey = async ( export const getConfigFilePath = (configDir: string): string => path.join(configDir, ".ai-cli"); -export const getDefaultCommandPrompt = (): string => +// Directly from - https://github.com/abhagsain/ai-cli/issues/9#issuecomment-1324016570 +const getPowerShellPrompt = () => + "Correctly answer the asked question. Return 'Sorry, Can't answer that.' if the question isn't related to technology.\n\nQ - get into a docker container.\nA - `docker exec -it `\n\nQ - Check what's listening on a port.\nA - `netstat -ano | findstr :`\n\nQ - How to ssh into a server with a specific file.\nA - `ssh -i @`\n\nQ - How to set relative line numbers in vim.\nA - `:set relativenumber`\n\nQ - How to create alias?\nA - `Set-Alias `\n\nQ - Tail docker logs.\nA - `docker logs -f mongodb`\n\nQ - Forward port in kubectl.\nA - `kubectl port-forward 8080:3000`\n\nQ - Check if a port is accessible.\nA - `Test-NetConnection -ComputerName -Port `\n\nQ - Kill a process running on port 3000.\nA - `Get-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess | Stop-Process`\n\nQ - Backup database from a mongodb container.\nA - `docker exec -it mongodb bash -c \"mongoexport --db mongodb --collection collections --outdir backup\"`\n\nQ - SSH Tunnel Remote Host port into a local port.\nA - `ssh -L :: @`\n\nQ - Copy local file to S3.\nA - `aws s3 cp s3:///`\n\nQ - Copy S3 file to local.\nA - `aws s3 cp s3:/// `\n\nQ - Recursively remove a folder.\nA - `Remove-Item -Recurse `\n\nQ - Copy a file from local to ssh server.\nA - ` scp /path/to/file user@server:/path/to/destination`\n\nQ - Download a file from a URL.\nA - `Invoke-WebRequest -Uri -OutFile `\n\nQ - Git commit with message.\nA - `git commit -m \"my commit message\"`\n\nQ - Give a user sudo permissions.\nA - `Add-LocalGroupMember -Group \"Administrators\" -Member `\n\nQ - Check what's running on a port?\nA - `Get-Process -Id (Get-NetTCPConnection -LocalPort ).OwningProcess`\n\nQ - View last 5 files from history\nA - `Get-History -Count 5`\n\nQ - When was China founded?\nA - Sorry, Can't answer that.\n\nQ - Filter docker container with labels\nA - `docker ps --filter \"label=\"`\n\nQ - When was Abraham Lincon born?\nA - Sorry, Can't answer that.\n\nQ - Get into a running kubernetes pod\nA - `kubectl exec -it bash`\n\nQ - Capital city of Ukrain?\nA - Sorry, Can't answer that.\n\nQ - "; + +const getUnixPrompt = () => 'Correctly answer the asked question. Return \'Sorry, Can\'t answer that.\' if the question isn\'t related to technology.\n\nQ - get into a docker container.\nA - `docker exec -it mongodb`\n\nQ - Check what\'s listening on a port.\nA - `lsof -i tcp:4000`\n\nQ - How to ssh into a server with a specific file.\nA - `ssh -i ~/.ssh/id_rsa user@127.0.0.1`\n\nQ - How to set relative line numbers in vim.\nA - `:set relativenumber`\n\nQ - How to create alias?\nA - `alias my_command="my_real_command"`\n\nQ - Tail docker logs.\nA - `docker logs -f mongodb`\n\nQ - Forward port in kubectl.\nA - `kubectl port-forward 8080:3000`\n\nQ - Check if a port is accessible.\nA - `nc -vz host port`\n\nQ - Reverse SSH Tunnel Syntax.\nA - `ssh -R :: @`\n\nQ - Kill a process running on port 3000.\nA - `lsof -ti tcp:3000 | xargs kill`\n\nQ - Backup database from a mongodb container.\nA - `docker exec -it mongodb bash -c "mongoexport --db mongodb --collection collections --outdir backup"`\n\nQ - SSH Tunnel Remote Host port into a local port.\nA - `ssh -L :: @`\n\nQ - Copy local file to S3.\nA - `aws s3 cp s3:///`\n\nQ - Copy S3 file to local.\nA - `aws s3 cp s3:/// `\n\nQ - Recursively remove a folder.\nA - `rm -rf `\n\nQ - Copy a file from local to ssh server.\nA - ` scp /path/to/file user@server:/path/to/destination`\n\nQ - Curl syntax with port.\nA - `curl http://localhost:3000`\n\nQ - Download a file from a URL with curl.\nA - `curl -o `\n\nQ - Git commit with message.\nA - `git commit -m "my commit message"`\n\nQ - Give a user sudo permissions.\nA - `sudo usermod -aG sudo `\n\nQ - Check what\'s running on a port?\nA - `lsof -i tcp:`\n\nQ - View last 5 files from history\nA - `history | tail -5`\n\nQ - When was China founded?\nA - Sorry, Can\'t answer that.\n\nQ - Pass auth header with curl\nA - `curl -H "Authorization: Bearer " `\n\nQ - Filter docker container with labels\nA - `docker ps --filter "label="`\n\nQ - When was Abraham Lincon born?\nA - Sorry, Can\'t answer that.\n\nQ - Get into a running kubernetes pod\nA - `kubectl exec -it bash`\n\nQ - Capital city of Ukrain?\nA - Sorry, Can\'t answer that.\n\nQ - '; + +export const getDefaultCommandPrompt = (): string => { + const platform = process.platform; + + switch (platform) { + case "win32": + return getPowerShellPrompt(); + + default: + return getUnixPrompt(); + } +};