WSL下的org能粘贴剪贴板中的图片吗?

试了org–download和论坛上一些人的linux下的方法都不好用,求解一下,谢谢

好像审题错误,下面两个使用流程是:截图->复制-> call function

——————————————————

自己动手

(defun my-yank-image-from-win-clipboard-through-powershell()
  "to simplify the logic, use c:/Users/Public as temporary directoy, then move it into current directoy

Anyway, if need to modify the file name, please DONT delete or modify file extension \".png\",
otherwise this function don't work and don't know the reason
"
  (interactive)
  (let* ((powershell "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
         (file-name (format "%s" (read-from-minibuffer "Img Name:" (format-time-string "screenshot_%Y%m%d_%H%M%S.png"))))
         ;; (file-path-powershell (concat "c:/Users/\$env:USERNAME/" file-name))
         (file-path-wsl (concat "./images/" file-name)))
    (if (file-exists-p "./images")
        (ignore)
      (make-directory "./images"))
    ;; (shell-command (concat powershell " -command \"(Get-Clipboard -Format Image).Save(\\\"C:/Users/\\$env:USERNAME/" file-name "\\\")\""))
    (shell-command (concat powershell " -command \"(Get-Clipboard -Format Image).Save(\\\"C:/Users/Public/" file-name "\\\")\""))
    (rename-file (concat "/mnt/c/Users/Public/" file-name) file-path-wsl)
    (format "%s" file-path-wsl)
    ))

(defun my-yank-image-link-into-org-from-wsl ()
  "call `my-yank-image-from-win-clipboard-through-powershell' and insert image file link with org-mode format"
  (interactive)
  (let* ((file-path (my-yank-image-from-win-clipboard-through-powershell))
         (file-link (format "[[file:%s][%s]]" file-path (file-name-sans-extension (file-name-nondirectory file-path))))
         )
    (insert file-link)
    ))

1 个赞

https://github.com/schspa/emacs-c-ide-demo/blob/master/custom/setup-wsl.el 这个是我的配置,可以参考一下,不过最近已经不用windows了。

1 个赞

非常感谢您回复,但是使用过程中会出现如下提示:

我使用的WSL2,我检查过这两个目录确实存在且创建成功了,但截图文件不能正常生成,不知道是不是这个原因?