How to use the command 'grip' (with examples)
GitHub-flavoured Markdown (GFM) is a popular syntax for formatting text on GitHub. When working on Markdown files, it is often useful to preview them locally before pushing to GitHub. This is where the grip
command comes in handy. grip
is a tool that allows users to preview GFM files locally by starting a server and rendering the Markdown files in the browser.
Use case 1: Preview the rendered README
file of the current directory
Code:
grip
Motivation: Sometimes, it’s necessary to preview the rendered README
file of a project before pushing changes to GitHub. By running grip
without any arguments, it starts a server and serves the rendered README
file of the current directory. This allows developers to preview and verify their changes locally.
Explanation: When executed without any arguments, the grip
command starts a server and serves the rendered README
file in the browser. By default, it looks for a file named README.md
in the current directory.
Example output: The grip
command will start a server on a local address (e.g., http://localhost:6419
) and the rendered README
file will be displayed in the browser.
Use case 2: Serve a specific Markdown file
Code:
grip path/to/file.md
Motivation: There may be instances when you want to preview a specific Markdown file other than the README
file. By specifying the path to the desired Markdown file, the grip
command allows you to serve and preview that file locally in the browser.
Explanation: By providing the path/to/file.md
argument, the grip
command serves and renders the specified Markdown file in the browser. Replace path/to/file.md
with the actual file path.
Example output: The grip
command will start a server on a local address (e.g., http://localhost:6419
) and the specified Markdown file will be rendered and displayed in the browser.
Use case 3: Open the README
file of the current directory in the browser
Code:
grip --browser
Motivation: If you simply want to open the README
file of the current directory in the browser without explicitly specifying the file path, this use case is handy. It saves time by automatically opening the README
file in the default browser.
Explanation: The --browser
argument is used to indicate that the grip
command should open the README
file in the browser automatically. This is particularly useful when you only want to view the README
file and do not need to preview any specific Markdown file.
Example output: The grip
command will start a server on a local address (e.g., http://localhost:6419
) and the README
file of the current directory will be rendered and displayed in the default browser.
Use case 4: Serve the rendered README
file of the current directory on a specified port
Code:
grip port
Motivation: In some cases, you may want to use a specific port for the grip
server instead of relying on the default port. This use case allows you to specify a port number and start the server accordingly.
Explanation: By replacing port
with the desired port number, the grip
command starts the server on that specific port. This allows you to navigate to that port in the browser and view the rendered README
file of the current directory.
Example output: The grip
command will start a server on the specified port (e.g., http://localhost:3000
) and the rendered README
file of the current directory will be displayed in the browser.
Conclusion:
The grip
command is a convenient tool for previewing GitHub-flavoured Markdown files locally. By using the different use cases mentioned above, developers can easily preview, review, and verify their Markdown files before pushing them to GitHub. Whether it’s serving the README
file, opening it in the browser, or customizing the server port, grip
provides a versatile solution for local Markdown rendering.