Skip to content

Instantly share code, notes, and snippets.

@joshuaclayton
Last active April 8, 2018 02:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshuaclayton/b945ecc797dcfdb001c10790c954046e to your computer and use it in GitHub Desktop.
Save joshuaclayton/b945ecc797dcfdb001c10790c954046e to your computer and use it in GitHub Desktop.

This is a rough draft (which works!) handling file composition for vim-projectionist.

Each of the *.json files live in ~/.projections, and projections lives somewhere in your $PATH. This uses jq to combine multiple JSON files into one. With navigation.zsh, we hook into cding into a directory, run projections, and if there's a 0 exit code, overwrite the output to .projections.json, which vim-projectionist then uses.

I've updated my ~/.gitignore to ignore .projections.json, so I'm not concerned about things messing up git.

{
"lib/*.ex": {
"type": "source",
"alternate": "test/lib/{}_test.exs"
},
"*": {
"make": "mix test"
},
"test/*_test.exs": {
"command": "test",
"dispatch": "mix test {file}"
}
}
{
"src/*.hs": {
"type": "source",
"alternate": "test/{camelcase}Spec.hs"
},
"app/Main.hs": {
"type": "main"
},
"app/App.hs": {
"type": "app"
}
}
function chpwd {
local v=$(projections)
if [[ $? -eq 0 ]]; then
echo $v > .projections.json
fi
}
{
"priv/repo/migrations/*.exs": {
"type": "migration"
},
"web/models/*.ex": {
"type": "model",
"alternate": "test/models/{}_test.exs"
},
"web/controllers/*_controller.ex": {
"type": "controller",
"alternate": "test/controllers/{}_controller_test.exs",
"template": "defmodule AppName.{camelcase}Controller\n use AppName.Web, :controller\nend"
},
"web/channels/*_channel.ex": {
"type": "channel",
"alternate": "test/channels/{}_test.exs",
"template": "defmodule AppName.Channels.{camelcase}Channel\n use Phoenix.Channel\n\n def join(_topic, _params, socket) do\n {open}:ok, socket{close}\n end\nend"
},
"web/encoders/*.ex": {
"type": "encoder",
"alternate": "test/encoders/{}_test.exs"
},
"web/plugs/*.ex": {
"type": "plug",
"alternate": "test/plug/{}_test.exs",
"template": "defmodule AppName.Plugs.{camelcase}\n import Plug.Conn\n\n def init(opts), do: opts\nend"
},
"web/services/*.ex": {
"type": "service",
"alternate": "test/services/{}_test.exs",
"template": "defmodule AppName.{camelcase}\n\nend"
},
"web/views/*.ex": {
"type": "view",
"alternate": "test/views/{}_test.exs",
"template": "defmodule AppName.{camelcase}View\n use AppName.Web, :view\nend"
},
"web/templates/*.html.eex": {
"type": "template"
},
"web/templates/layout/*.html.eex": {
"type": "layout"
},
"web/static/js/*": {
"type": "js"
},
"web/static/css/*": {
"type": "css"
},
"web/router.ex": {
"type": "router"
},
"test/controllers/*_test.exs": {
"alternate": "web/controllers/{}.ex",
"template": "defmodule AppName.{camelcase}Test\n use AppName.ConnCase\nend"
},
"test/models/*_test.exs": {
"alternate": "web/models/{}.ex",
"template": "defmodule AppName.{camelcase}Test\n use AppName.ConnCase\nend"
},
"test/support/factories.ex": {
"command": "factories"
},
"*": {
"make": "mix test",
"console": "iex -S mix phoenix.server",
"start": "mix phoenix.server"
},
"test/*_test.exs": {
"command": "test",
"dispatch": "mix test {file}"
}
"*": {
"make": "mix test",
"console": "iex -S mix phoenix.server",
"start": "mix phoenix.server"
},
}
#!/usr/bin/env bash
PROJECTIONS_PATH="$HOME/.projections"
list=()
if [ -f "mix.exs" ]; then list+=('elixir'); fi
if [ -f "web/router.ex" ]; then list+=('phoenix'); fi
if [ -f "app/Main.hs" ]; then list+=('haskell'); fi
if [ -f "Rakefile" ]; then list+=('rake'); fi
if [ -f "spec/spec_helper.rb" ]; then list+=('rspec'); fi
if [ -f "config/routes.rb" ]; then list+=('rails'); fi
__gemspec=(*.gemspec)
if [ -f "${__gemspec[0]}" ]; then list+=('ruby'); fi
files=''
count=0
while [ "x${list[count]}" != "x" ]; do
files="$files $PROJECTIONS_PATH/${list[count]}.json"
count=$((count + 1))
done
if [ $count -eq 0 ]; then exit 1; fi
jq -s 'reduce .[] as $item ({}; . * $item)' $files
{
"Rakefile": {
"type": "rakefile"
},
"lib/tasks/*.rake": {
"type": "task"
}
}
{
"spec/spec_helper.rb": {
"type": "spechelper"
},
"spec/support/*.rb": {
"type": "support"
},
"spec/features/*.rb": {
"type": "feature"
},
"spec/acceptance/*.rb": {
"type": "feature"
},
"spec/requests/*.rb": {
"type": "request"
},
"spec/integration/*.rb": {
"type": "integration"
},
"spec/*.rb": {
"type": "spec"
}
}
{
"*.gemspec": {
"type": "gemspec"
},
"lib/*.rb": {
"type": "lib",
"alternate": "spec/{}_spec.rb"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment