ajeetdsouza / zoxide

A smarter cd command. Supports all major shells.
MIT License
20.54k stars 523 forks source link

[Informational] How to import from `jump` #706

Open grignaak opened 5 months ago

grignaak commented 5 months ago

I moved my data from gsamokovarov's jump to zoxide using the following jq command.

The interesting parts are

This version removes the local timezone offset altogether, using the machine's local offset.

cat >/tmp/jump-import.jq <<'COMMAND'
def pytime:
  sub("\\..*"; "") |
  strptime("%Y-%m-%dT%H:%M:%S")
  ;
map(.Path  + "|"  + (.Score.Weight | tostring)  + "|"  + (.Score.Age | pytime | strftime("%s"))) | .[]
COMMAND
<~/.jump/scores.json | jq -r -f /tmp/jump-import.jq | tee /tmp/jump-db.txt
zoxide import --from z /tmp/jump-db.txt

This definition keeps the local timezone by stripping the colon out of the offset (if you care about exact age AND you move from timezone to timezone):

def pytime:
  sub("(\\.\\d+)?(?<o>[-+](\\d+))(:(?<s>[^:]+))?$"; "\(.o)\(.s)") |
  strptime("%Y-%m-%dT%H:%M:%S%z")
  ;

[Edit] Here is a snippet of my ~/.jump/scores.json to show the structure.

[
  {
    "Path": "/Users/grignaak/.local/opt/tim",
    "Score": {
      "Weight": 38,
      "Age": "2024-02-16T01:14:47.209456-08:00"
    }
  },
  {
    "Path": "/Users/grignaak",
    "Score": {
      "Weight": 22,
      "Age": "2024-02-16T01:14:49.689344-08:00"
    }
  },
  {
    "Path": "/Users/grignaak/workplace/flow/src/ConfigurationService",
    "Score": {
      "Weight": 5,
      "Age": "2024-02-02T23:06:44.827113-08:00"
    }
  },
  {
    "Path": "/Users/grignaak/workplace/flow/src/CanaryService",
    "Score": {
      "Weight": 5,
      "Age": "2024-02-07T12:02:33.058661-08:00"
    }
  },
  {
    "Path": "/Volumes/workplace/flow/src",
    "Score": {
      "Weight": 4,
      "Age": "2024-02-02T11:32:45.948023-08:00"
    }
  }
]