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

How to regenerate correct IDs? #67

Closed
OrionRandD opened this issue Jun 11, 2020 · 4 comments
Closed

How to regenerate correct IDs? #67

OrionRandD opened this issue Jun 11, 2020 · 4 comments

Comments

@OrionRandD
Copy link

I made a mistake setting up my IDs and some of my files look like this:
10-06-2020-22:53 python_automateBSW01.org
The problem is that this format does not create a proper ID when I tell zetteldeft to copy the current ID. It only shows the paragraph symbol with no identification.
Then I reinstalled zetteldeft and the files are ok, generating correct IDs like that:
2020-05-16-1139 python_course-AtBSwP.org
Question: How do I fix my files with this ID format 10-06-2020-22:53 python_automateBSW01.org to be like this 2020-05-16-1139 python_course-AtBSwP.org. I think the (:) colon spoiled some of my files IDs.
Do I have to recreate all those files copying and pasting the contents or there is a way to batch fix all the files with the (:) colon IDs?

@gklimowicz
Copy link

Hopefully you're on Unix or a Mac or on Windows with the Unix subsystem or Cygwin. Here's what I do when I get in this situation. Get to a shell, and cd to the directory with your badly named files. Execute the following command. Make sure the output looks the way you expect it to. It will produce a sequence of mv commands to rename your files. (If your files have apostrophes (') in the name, you'll need a bit more to make this work.)

/bin/ls *:* \
| sed -e "s/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)-\([0-9][0-9]\):\([0-9][0-9]\)\( .*\)/mv '&' '\3-\2-\1-\4\5\6'/"

When run on a directory containing a file named after your example, it produces this:

mv '10-06-2020-22:53 python_automateBSW01.org' '2020-06-10-2253 python_automateBSW01.org'

When you're satisfied this is the right output, pipe the output of that to the shell to execute the renames.

/bin/ls *:* \
| sed -e "s/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)-\([0-9][0-9]\):\([0-9][0-9]\)\( .*\)/mv '&' '\3-\2-\1-\4\5\6'/" \
| sh

Here's an example on a directory containing the file you mention:

$ ls
10-06-2020-22:53 python_automateBSW01.org
$ /bin/ls *:* \
| sed -e "s/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)-\([0-9][0-9]\):\([0-9][0-9]\)\( .*\)/mv '&' '\3-\2-\1-\4\5\6'/"
mv '10-06-2020-22:53 python_automateBSW01.org' '2020-06-10-2253 python_automateBSW01.org'
$ /bin/ls *:* \
| sed -e "s/\([0-9][0-9]\)-\([0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)-\([0-9][0-9]\):\([0-9][0-9]\)\( .*\)/mv '&' '\3-\2-\1-\4\5\6'/" \
| sh
$ ls
2020-06-10-2253 python_automateBSW01.org

(Variations on this theme are how I have migrated tons of files into the appropriate format for my Zettelkasten.)

@OrionRandD
Copy link
Author

Thx a lot for the fix! It worked greatly.
I think that there should be an option/feature in zetteldeft for fixing
file IDs when people face the same-like issue.
But I will copy this fix to a local file in case I need it again.

Another thing is that I wonder if this setup is right or I can improve it in my init.org:

(use-package zetteldeft
:ensure t
:after deft
:config
(zetteldeft-set-classic-keybindings)
(setq deft-new-file-format zetteldeft-id-format))

(defun zetteldeft-generate-id ()
"Generate an ID in the format of `zetteldeft-id-format'."
(format-time-string zetteldeft-id-format))

(require 'zetteldeft)
;; (zetteldeft-set-classic-keybindings)

It is working, but perhaps I can improve the syntax.

Also I would like to change the auto-saving time in my deft in the init.org. I know how to change it in my deft.el, but this solution is not good because when MELPA updates deft, I have to set auto-save time again. Here is my deft setup in init.org:

(use-package deft
:ensure t
:custom
(deft-extensions '("org" "md" "txt"))
(deft-directory "/org/deft-notes")
(deft-use-filename-as-title t))

   (defun cypher/deft-open-other ()
   (interactive)
   (deft-open-file-other-window t))

   (defun cypher/deft-open-preview ()
   (interactive)
   (deft-open-file-other-window))

(with-eval-after-load 'deft
(define-key deft-mode-map
(kbd "") 'cypher/deft-open-preview)
(define-key deft-mode-map
(kbd "") 'cypher/deft-open-other)
(define-key deft-mode-map
(kbd "s-j") 'evil-next-line)
(define-key deft-mode-map (kbd "s-k") 'evil-previous-line))

(setq deft-strip-summary-regexp
(concat "\("
"[\n\t]" ;; blank
"\|^#\+[a-zA-Z_]+:.*$" ;;org-mode metadata
"\)"))

I wonder where I should set the auto-save time in this deft setup to save every 30 seconds and how to add this in the above use-package configuration.

:)

@gklimowicz
Copy link

gklimowicz commented Jun 11, 2020

With respect to zetteldeft having an option to rename IDs, I will admit that I'm not a fan. Let zetteldeft be zetteldeft. I like that it focuses on making the note-taking, linking and discovery workflow nearly frictionless for me.

I've not used :custom with use-package. I tend to put all my initializations into the :config section, like this:

 :config
  (progn
    (setq deft-directory "~/Documents/ZK")
    (setq deft-recursive t)
    (setq deft-filter-only-filenames t)
    (setq deft-file-limit 200)
    (setq deft-auto-save-interval 0)
    ...)

The progn isn't necessary, but I like the way things indent better and it's easier to traverse the use-package with C-M-f and C-M-b.

@OrionRandD
Copy link
Author

Thx for the suggestion. I've fixed everything now.
:)

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

3 participants