Espanso: How to insert tomorow and yesterday dates?

Created on 5 Jun 2020  Â·  15Comments  Â·  Source: federico-terzi/espanso

Feature RFNR

Most helpful comment

You can do it with shell integration if your system has the date program.

  - trigger: ";tomorrow"
    replace: "Tomorrow is {{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "date -v+1d +%D"
  • The +1d is the time adjustment and can also take - for past times.
  • The +%D controls the formatting and allows you to do other things like make it say "Monday" with %A (look up the strftime codes for more options). As of writing this, tomorrow is Monday.
  • Also the framing text in the replacement is just for the demo but you can also just make it say {{output}} if you only want the date itself and no message.

I don't think this is helpful for windows users, though.

All 15 comments

Hey,

This could be a very useful feature indeed, I'll add it to the roadmap!

Cheers :)

You can do it with shell integration if your system has the date program.

  - trigger: ";tomorrow"
    replace: "Tomorrow is {{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "date -v+1d +%D"
  • The +1d is the time adjustment and can also take - for past times.
  • The +%D controls the formatting and allows you to do other things like make it say "Monday" with %A (look up the strftime codes for more options). As of writing this, tomorrow is Monday.
  • Also the framing text in the replacement is just for the demo but you can also just make it say {{output}} if you only want the date itself and no message.

I don't think this is helpful for windows users, though.

For those who uses Windows10 with Linux Subsystem

  - trigger: ":1date"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "bash -c 'date +%Y-%m-%d -d +1day'"

Hey @mrjackphil,
Thank you for pointing this out. To complement your answer, I'd like to say that since espanso 0.6.0 you can use WSL directly with the "wsl" parameter:

  - trigger: ":1date"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "date +%Y-%m-%d -d +1day"
          shell: wsl

Cheers :)

@federico-terzi Just tried it and it works not as I expected. Maybe because of Cyrillic symbols or different format. While my configuration returns:


when tried yours I receive:

������� �������⨬�� ���.
������ ����� ���� (��-��-��): 

Thank you for pointing that out @mrjackphil, this seems like a bug! Could you please tell me which language are you using? If I manage to reproduce it I might be able to get a solution :)

I'm using a Windows 10 Home Edition. Russian language.

All right, thank you @mrjackphil

Just a heads up, date under macOS needs the -v argument, but that will cause date under Linux to give an error. If you use Espanso under both OSes, you'll probably need a script to use the correct version of date.

@mrrcollins thanks for your feedback, I've opened an issue to make this handling more convenient #353

Just wanted to let you know that the next release (0.7.0) will support this out of the box. In particular, you will be able to specify an offset parameter that takes the number of seconds of offset.
For example:

  - trigger: ":yesterday"
    replace: "{{mytime}}"
    vars:
    - name: mytime
      type: date
      params:
        format: "%c"
        offset: -86400
  - trigger: ":tomorrow"
    replace: "{{mytime}}"
    vars:
    - name: mytime
      type: date
      params:
        format: "%c"
        offset: 86400

Very good!!!

PLS @mrjackphil
What is wrong here?...

  - trigger: ":fecha"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "date /t"

It does nothing! (W10)

@jczanfona You should be able to get it working by specifying the cmd shell:

  - trigger: ":fecha"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "date /t"
          shell: cmd

By default espanso uses Powershell on Windows, which as far as I know does not support the date command

Cheers :)

TX a lot @federico-terzi
Great sw !!!

Was this page helpful?
0 / 5 - 0 ratings