promptops / cli

um is a GPT-powered CLI assistant. Ask questions in plain English, get the perfect shell command.
https://promptops.com
GNU General Public License v3.0
122 stars 3 forks source link

custom shell config location #13

Closed LangLangBart closed 1 year ago

LangLangBart commented 1 year ago

info

$SHELL --version
zsh 5.8 (x86_64-apple-darwin17.7.0)

description

um --version
0.1.10
latest version: 0.1.7
grep: /Users/paria/.zshrc: No such file or directory

Warning: um is not fully configured. To finish the installation, run:
  eval "$(um --install)"
um --config

  📢 provide your email address to receive occasional updates and tips (optional, leave blank to skip)
>

  👋 thanks for installing um! let's make sure you get the most out of it

 ➜︎ continue
   skip

  📖 indexing your history can greatly improve the speed and the quality of the suggestions
  do you want to index your history? we take special care to scrub secrets before indexing

 ➜︎ confirm
   skip
Progress: [                                                  ] 1.0%Traceback (most recent call last):
  File "/usr/local/bin/um", line 33, in <module>
    sys.exit(load_entry_point('promptops==0.1.10', 'console_scripts', 'um')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/promptops-0.1.10-py3.11.egg/promptops/main.py", line 198, in entry_alias
  File "/usr/local/lib/python3.11/site-packages/promptops-0.1.10-py3.11.egg/promptops/user.py", line 143, in register
  File "/usr/local/lib/python3.11/site-packages/promptops-0.1.10-py3.11.egg/promptops/user.py", line 74, in config_flow
  File "/usr/local/lib/python3.11/site-packages/promptops-0.1.10-py3.11.egg/promptops/history.py", line 78, in index_history
  File "/usr/local/lib/python3.11/site-packages/promptops-0.1.10-py3.11.egg/promptops/shells/zsh.py", line 48, in get_recent_history
  File "/usr/local/lib/python3.11/site-packages/promptops-0.1.10-py3.11.egg/promptops/shells/base.py", line 36, in reverse_readline
FileNotFoundError: [Errno 2] No such file or directory: '/Users/paria/.zsh_history'

[...] type 'print $ZDOTDIR' and if you get something other than a blank line, or an error message telling you the parameter isn't set, it's telling you a directory other than '~' where your startup files live [...]

 print $ZDOTDIR
# /Users/paria/.dotfiles/zsh

ls /Users/paria/.dotfiles/zsh
# .p10k.zsh       .p10k.zsh.zwc   .zsh_history    .zshenv         .zshrc

ls -la /Users/paria | grep zsh
# lrwxr-xr-x    1 paria  staff     29 May  7 07:01 .zshenv -> /Users/paria/.dotfiles/zshenv

cat /Users/paria/.zshenv
# ZDOTDIR=~/.dotfiles/zsh
# source -- "$ZDOTDIR"/.zshenv

expected behavior


--- a/promptops/shells/zsh.py
+++ b/promptops/shells/zsh.py
@@ -30,7 +30,11 @@ def unmetafy(cmd: bytes) -> (bytes, bytes):
 class Zsh(Shell):
     def __init__(self, history_file: str = None):
         if not history_file:
-            history_file = os.getenv("HISTFILE", "~/.zsh_history")
+            zdotdir = os.getenv("ZDOTDIR")
+            if zdotdir:
+                history_file = os.path.join(zdotdir, ".zsh_history")
+            else:
+                history_file = os.getenv("HISTFILE", "~/.zsh_history")
         super().__init__(history_file)

     def get_recent_history(self, look_back: int = 10):
@@ -121,4 +125,9 @@ um() {{
 }}""".strip()

     def _get_config_file(self):
+        zdotdir = os.getenv("ZDOTDIR")
+        if zdotdir:
+            config_file = os.path.join(zdotdir, ".zshrc")
+            if os.path.exists(config_file):
+                return config_file
         return "~/.zshrc"
jj-ctrlstack commented 1 year ago

@LangLangBart thanks for logging the issue and the proposed fix! Feel free to send PR and we'll merge it.

jj-ctrlstack commented 1 year ago

@LangLangBart we are getting ready to release new version so I just pushed code to take care of this. Thanks for bringing this up and the suggested fix!

jj-ctrlstack commented 1 year ago

fixed in 0.1.11