Skip to content

Instantly share code, notes, and snippets.

@ajitid
Created July 25, 2021 15:06
Show Gist options
  • Save ajitid/31bee3a7845093c29fb009f5b66caeb6 to your computer and use it in GitHub Desktop.
Save ajitid/31bee3a7845093c29fb009f5b66caeb6 to your computer and use it in GitHub Desktop.
automate vim using neovim-remote
function jqdoprocessoneach
# https://stackoverflow.com/a/965106/7683365
set -l old_file_path $argv[1]
set -l new_filename $argv[2]"."(echo $argv[1] | sed 's/.*\.//')
echo $old_file_path
# echo $new_filename
# sleep 1
nvr --remote-send '<cmd>e '$old_file_path'<cr>'
sleep 1
nvr --remote-send '<cmd>TSLspRenameFile<cr>'
nvr --remote-send '<c-w><c-w><c-w>'
nvr --remote-send $new_filename'<cr>'
sleep 3
nvr --remote-send '<cmd>wa<cr>'
sleep 1
end
function jqdo
if [ "$argv[1]" = "" ]
echo 'please give a filename to process'
return 1
end
# take [["oldfilepath", "newfilenamewithoutextension"], ...] to
# ```
# oldfilepath
# newfilenamewithoutextension
# ...
# ```
cat $argv[1] | jq '.[] | map(.) | .[0],.[1]' | sed -e 's/^"//' -e 's/"$//' | xargs -n 2 -P 1 fish -c 'source s.fish; jqdoprocessoneach $argv'
end
@ajitid
Copy link
Author

ajitid commented Jul 25, 2021

To run it, I used, source s.fish followed by jqdo a.json. This script is renaming TS files using LSP to make sure its references are updated too.

Example a.json:

[
  [
    "src/components/SomeComponent/SomeComponentStyles.tsx",
    "useStylesForSomeComponent"
  ],
  [
    "--- second file full path from root ---",
    "--- new filename without extension ---"
  ],
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment