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

[Informational] How to import from jump #706

Open
grignaak opened this issue Feb 16, 2024 · 0 comments
Open

[Informational] How to import from jump #706

grignaak opened this issue Feb 16, 2024 · 0 comments

Comments

@grignaak
Copy link

grignaak commented Feb 16, 2024

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

The interesting parts are

  • It uses a frecency algorithm so the scores can be imported by converting it to the z format first.
  • On MacOs/linux the jump database is ~/.jump/scores.json
  • Python can output a format that doesn't comply with standard strptime, so the jq script has to fix that by stripping out the microseconds fixing the timezone offset.

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"
    }
  }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant