Created
March 22, 2022 21:38
-
-
Save dblevins/703b85bce270ced82bb8f026bdc9ccc0 to your computer and use it in GitHub Desktop.
Mac clipboard manipulation scripts I use the most. These all live in my ~/bin/ directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Useful for when you want to trim off leading spaces from clipboard text | |
# Say you grab a chunk of code from a markdown document and want to remove | |
# the four spaces at the front: | |
# | |
# pbcut -c 5- | |
pbpaste | cut "$@" | pbcopy | |
pbpaste |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Useful for when you want to add spaces in front of some text. Perhaps | |
# you want something to appear as code in a Markdown document, just run | |
# pbindent twice. Indented text also looks nice in emails to make something | |
# appear as a quote of a document or contents of a file. | |
pbpaste | perl -pe 's/^/ /' | pbcopy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Will prepend the given prefix onto each line of the clipboard. | |
# Very useful for when you have some text you want to turn into | |
# a bulleted list. | |
# | |
# pbprefix " - " | |
# | |
# Maybe you want some text to appear as quoted in an email: | |
# | |
# pbprefix "> " | |
# | |
PREFIX="${1?Specify a prefix such as a dash or bullet}" | |
pbpaste | perl -pe "s/^/$PREFIX/" | pbcopy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This clipboard text would be better if it was sorted, right? | |
# Options can be passed to the sort command, so for example to | |
# sort the clipboard text numerically: | |
# | |
# pbsort -n | |
# | |
pbpaste | sort "$@" | pbcopy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# For when you don't want the fonts, colors and other fancy | |
# formatting information. Yes, there are hot keys for that, but | |
# I live in the terminal anyway and have all these other commands | |
# so why not. | |
pbpaste | pbcopy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Would it be nice if this text was word-wrapped? Sure, | |
# we can paste it into emacs, wrap it, then copy it back, | |
# but perhaps this is a bit quicker. | |
# | |
# pbwrap | |
# pbwrap 77 | |
# | |
WIDTH="${1:-90}" | |
echo $(pbpaste) | fold -w "$WIDTH" -s | pbcopy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment