Skip to content

feat: add _mnn#51

Draft
michen00 wants to merge 1 commit intomainfrom
002-mnn-clipboard-en-em
Draft

feat: add _mnn#51
michen00 wants to merge 1 commit intomainfrom
002-mnn-clipboard-en-em

Conversation

@michen00
Copy link
Owner

Description

Have you ever Googled 'en dash' or 'em dash' just so you can copy and paste it somewhere? Say less. Push an en dash (U+2013) or an em dash (U+2014) onto your clipboard with single command:

  • em_ for an em dash: —
  • en_ for an en dash: –

Inspiration: https://github.com/rskottap/personal/blob/master/bin/emoji

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @michen00, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a convenient new feature that allows users to quickly copy typographic em dashes (—) and en dashes (–) to their system clipboard using simple shell commands, em_ and en_ respectively. The implementation is robust, featuring cross-platform compatibility for macOS, Linux (X11 and Wayland), and Windows, and includes thorough testing to ensure reliability across different environments and clipboard utilities.

Highlights

  • New Feature: Typographic Dash Commands: Introduced new em_ and en_ commands that allow users to quickly copy an em dash (—, U+2014) or an en dash (–, U+2013) to their system clipboard, respectively.
  • Cross-Platform Clipboard Support: The core script _mnn intelligently detects the operating system (macOS, Linux X11/Wayland, Windows) and uses the appropriate clipboard utility (pbcopy, xclip, xsel, wl-copy, clip.exe) to ensure broad compatibility.
  • Comprehensive Testing: A new BATS test suite (tests/_mnn.bats) has been added, covering script syntax, correct dash copying, clipboard content overwriting, platform-specific clipboard tool detection, help message display, and various error handling scenarios.
  • Documentation Update: The README.md file has been updated to include clear documentation for the new em_ and en_ commands, explaining their functionality and usage.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Repository owner deleted a comment from github-actions bot Jan 31, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a useful utility for copying en and em dashes to the clipboard. The cross-platform support in the _mnn script is well-implemented. My main feedback concerns the implementation of the em_ and en_ wrapper scripts, which are currently fragile. The standard and most maintainable way to implement this pattern is to use symbolic links. I've provided an alternative suggestion to use robust wrapper scripts to avoid code duplication and improve maintainability. I've also included a few suggestions to simplify and improve the main _mnn script.

Comment on lines +45 to +82
select_clipboard_command() {
local platform=$1
case "$platform" in
macos)
if command -v pbcopy >/dev/null 2>&1; then
echo "pbcopy"
else
echo "ERROR:pbcopy not found"
fi
;;
x11)
if command -v xclip >/dev/null 2>&1; then
echo "xclip -selection clipboard"
elif command -v xsel >/dev/null 2>&1; then
echo "xsel --clipboard"
else
echo "ERROR:xclip or xsel not found"
fi
;;
wayland)
if command -v wl-copy >/dev/null 2>&1; then
echo "wl-copy"
else
echo "ERROR:wl-copy not found"
fi
;;
windows)
if command -v clip.exe >/dev/null 2>&1; then
echo "clip.exe"
else
echo "ERROR:clip.exe not found"
fi
;;
*)
echo "ERROR:unsupported platform"
;;
esac
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Returning error messages as strings (e.g., ERROR:pbcopy not found) and checking for them with string comparisons is a viable but somewhat brittle approach. A more idiomatic and robust pattern in shell scripting, especially when using set -e, is to have functions report errors on stderr and return a non-zero exit code. The calling code can then rely on set -e to halt execution automatically on failure.

For example, select_clipboard_command could be refactored to echo errors to stderr and return 1. Then in main, you could simply call it and let the script exit if it fails.

Comment on lines +135 to +138
if [[ "$SCRIPT_NAME" == "_mnn" ]]; then
echo "Error: This script must be invoked as 'en_' or 'em_'" >&2
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This explicit check for _mnn is redundant. The select_dash function, which is called shortly after, already has a default *) case that handles any script name other than en_ or em_, including _mnn. You can safely remove this block to simplify the code.

Comment on lines +180 to +192
if [[ "$platform" == "windows" ]]; then
# Windows echo doesn't support -n flag
echo "$dash" | $clipboard_cmd || {
echo "Error: Failed to copy to clipboard: $?" >&2
exit 1
}
else
# Unix-like systems support echo -n
echo -n "$dash" | $clipboard_cmd || {
echo "Error: Failed to copy to clipboard: $?" >&2
exit 1
}
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of using a platform-specific if/else to handle the -n flag for echo, you can use printf. The printf "%s" "$dash" command is more portable and behaves consistently across different shells and operating systems, including Windows environments like MSYS/Cygwin. This simplifies your code by removing the conditional block.

	# Copy to clipboard
	printf "%s" "$dash" | $clipboard_cmd || {
		echo "Error: Failed to copy to clipboard: $?" >&2
		exit 1
	}

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

Successfully merging this pull request may close these issues.

1 participant