Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior for the "-on" flag #1843

Closed
aisneto opened this issue Jan 12, 2024 · 4 comments
Closed

Strange behavior for the "-on" flag #1843

aisneto opened this issue Jan 12, 2024 · 4 comments
Labels
needs more info Further information is requested support End user support

Comments

@aisneto
Copy link

aisneto commented Jan 12, 2024

Diagnostic output

jrnl: v4.1
Python: 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
OS: Linux 6.1.0-17-amd64

Current Behavior

I'm attempting to retrieve all entries from a randomly chosen day using a combination of commands. This should be easily achieved with the command: jrnl -on "$(jrnl --short | shuf -n 1 | cut -d' ' -f1)". However, my journal indicates that no entries were found. Interestingly, when I use echo "$(jrnl --short | shuf -n 1 | cut -d' ' -f1)", I receive the expected result for a day where there were indeed entries in my journal (e.g., 2023-11-24).

Here's where it gets perplexing. If I manually use the result prompted by that echo as an argument for the -on flag (e.g., jrnl -on 2023-11-24), I successfully retrieve entries. Additionally, if I use another flag, such as jrnl -from "$(jrnl --short | shuf -n 1 | cut -d' ' -f1)", I also retrieve entries correctly. It appears that the -on flag is encountering difficulties when directly reading the output."

Even more perplexing is that the command sometimes works, promptly retrieving all entries on a random day. I do not have a clue what is happening.

Expected Behavior

The retrieval of all entries on a random day

Repro Steps

Simply try to use the output from other bash code with the -on flag.

Debug output

 jrnl --debug -on "$(jrnl --short | shuf -n 1 | cut -d'-' -f1,2,3)"
┏━━━━━━━━━━━━━━━━━━━━━┓
┃  547 entries found                ┃
┗━━━━━━━━━━━━━━━━━━━━━┛
[14:26:18] DEBUG    Logging start                                     main.py:32
           DEBUG    Parsed args:                                      main.py:42
                    Namespace(debug=True, preconfig_cmd=None,                   
                    postconfig_cmd=None, filename=None,                         
                    template=None, on_date='\x1b[1m\x1b[30m2022-11-16           
                    09:45:00 AM\x1b[0m \x1b[1m\x1b[33m@phil\x1b[0m',            
                    today_in_history=False, month=None, day=None,               
                    year=None, start_date=None, end_date=None,                  
                    contains=None, strict=False, starred=False,                 
                    tagged=False, limit=None, excluded=[],                      
                    edit=False, delete=False, change_time=None,                 
                    export=False, tags=False, short=False,                      
                    config_override=[], config_file_path='', text=[],           
                    exclude_starred=False, exclude_tagged=False)                
           DEBUG    Reading configuration from file                install.py:91
                    /home/aisneto/.config/jrnl/jrnl.yaml                        
           DEBUG    Using configuration:                          install.py:117
                    "{                                                          
                        'colors': {                                             
                            'body': 'none',                                     
                            'date': 'black',                                    
                            'tags': 'yellow',                                   
                            'title': 'cyan'                                     
                        },                                                      
                        'default_hour': 9,                                      
                        'default_minute': 0,                                    
                        'editor': 'nvim',                                       
                        'encrypt': False,                                       
                        'highlight': True,                                      
                        'indent_character': '|',                                
                        'journals': {                                           
                            'default': {                                        
                                'encrypt': True,                                
                                'journal':                                      
                    '/home/aisneto/Documentos/Registros/Journal/j               
                    ournal.txt'                                                 
                            }                                                   
                        },                                                      
                        'linewrap': 79,                                         
                        'tagsymbols': '#@',                                     
                        'template': False,                                      
                        'timeformat': '%F %r',                                  
                        'version': 'v4.1'                                       
                    }"                                                          
           DEBUG    Using journal name: default                    config.py:206
           DEBUG    Updating configuration with specific journal   config.py:111
                    overrides:                                                  
                    {                                                           
                        'encrypt': True,                                        
                        'journal':                                              
                    '/home/aisneto/Documentos/Registros/Journal/jo              
                    urnal.txt'                                                  
                    }                                                           
           DEBUG    Scoped config:                                 config.py:120
                    {                                                           
                        'colors': {                                             
                            'body': 'none',                                     
                            'date': 'black',                                    
                            'tags': 'yellow',                                   
                            'title': 'cyan'                                     
                        },                                                      
                        'default_hour': 9,                                      
                        'default_minute': 0,                                    
                        'editor': 'nvim',                                       
                        'encrypt': True,                                        
                        'highlight': True,                                      
                        'indent_character': '|',                                
                        'journals': {                                           
                            'default': {                                        
                                'encrypt': True,                                
                                'journal':                                      
                    '/home/aisneto/Documentos/Registros/Journal/jo              
                    urnal.txt'                                                  
                            }                                                   
                        },                                                      
                        'linewrap': 79,                                         
                        'tagsymbols': '#@',                                     
                        'template': False,                                      
                        'timeformat': '%F %r',                                  
                        'version': 'v4.1',                                      
                        'journal':                                              
                    '/home/aisneto/Documentos/Registros/Journal/jo              
                    urnal.txt'                                                  
                    }                                                           
           DEBUG    open_journal 'default'                        Journal.py:473
[14:26:19] DEBUG    start                                   BaseEncryption.py:16
           DEBUG    start                           BasePasswordEncryption.py:19
           DEBUG    start                                 Jrnlv2Encryption.py:23
           DEBUG    decrypting                      BasePasswordEncryption.py:59
           DEBUG    decrypting                            Jrnlv2Encryption.py:55
           DEBUG    opened Journal with 547 entries               Journal.py:136
           DEBUG    Search mode: starting                      controller.py:203
           DEBUG    Search mode: has search args               controller.py:210
           DEBUG    count: 0                                   controller.py:253
┏━━━━━━━━━━━━━━━━━━━━┓
┃  no entries found               ┃

Other Information

No response

@aisneto aisneto added 🆕 New! bug Something isn't working labels Jan 12, 2024
@micahellison
Copy link
Member

Hi @aisneto, based on that log, it looks like the color codes in the output from jrnl --short might be messing with your next call to jrnl, or the other commands in your piped chain. It's sending a bunch of color codes and a tag to your final jrnl -on call:

on_date='\x1b[1m\x1b[30m2022-11-16 09:45:00 AM\x1b[0m \x1b[1m\x1b[33m@phil\x1b[0m'

If you first pipe its output to a color remover like ansi2txt before processing the output, does that help? You'll need to strip out that tag (@phil) also.

@micahellison micahellison added needs more info Further information is requested support End user support and removed bug Something isn't working 🆕 New! labels Jan 22, 2024
@aisneto
Copy link
Author

aisneto commented Jan 22, 2024

I've tried your recommendation using "aha", like this: jrnl -on "$(jrnl --short | shuf -n 1 | cut -d' ' -f1 | aha --black)"

Now I got it working. However, strangely enough, some tries did return "no entries". Still, I would say that the command this way works 9 of 10 times.

@micahellison
Copy link
Member

Hi @aisneto, I think the issue that your script is clearing the formatting with aha at the end when instead it'd be better off clearing the formatting at the beginning, before shuf and cut work on it, like so:

jrnl -on "$(jrnl --short | aha --black | shuf -n 1 | cut -d' ' -f1)"

@micahellison
Copy link
Member

I'm closing this to clear off my list, though feel free to tag me with a comment back here if you need any more help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info Further information is requested support End user support
Projects
None yet
Development

No branches or pull requests

2 participants