Last active
April 23, 2024 07:53
-
-
Save cesalazar/d64cffc85c635b4384307bc76b175fd8 to your computer and use it in GitHub Desktop.
clipbread config
This file contains hidden or 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
const { getClipboard } = require(`${process.mainModule.path}/utils`) | |
const { execSync } = require('child_process') | |
// Modify to your hearth's content! | |
// Function to run a command and return the output or error | |
const runCmd = (command) => { | |
try { | |
const output = execSync(command, { encoding: 'utf8' }) | |
return output | |
} catch (error) { | |
return error.message | |
} | |
} | |
const formatTextWidth = (width) => | |
runCmd(`echo "${getClipboard()}" | fmt -w${width}`) | |
// This uses my zsh/git aliases, you'll probably need to use `git checkout -b` | |
const gitCheckout = (kind = '') => | |
`g co -b ${kind ? kind + '/' : ''}${getClipboard()}` | |
const surroundWith = (start = '', end = '') => `${start}${getClipboard()}${end}` | |
const removeSurround = (start, end) => | |
getClipboard().replace(new RegExp(`${start}(\\s+)?|(\\s+)?${end}`, 'gm'), '') | |
const replaceTokens = (inn, out) => getClipboard().replace(inn, out) | |
const functions = { | |
case_SnakeToCamel: () => | |
replaceTokens(/_+./g, (match) => match.slice(-1).toUpperCase()), | |
caseCamelTo_Snake: () => replaceTokens(/([A-Z])+/g, '_$1').toLowerCase(), | |
checkoutBranch: () => gitCheckout(), | |
checkoutChoreBranch: () => gitCheckout('chore'), | |
checkoutFeatureBranch: () => gitCheckout('feature'), | |
checkoutFixBranch: () => gitCheckout('fix'), | |
cleanEncodedUrlTracking: () => | |
decodeURIComponent( | |
getClipboard().split(/\?.*?=/)[1] ?? getClipboard() | |
).split('&')[0], | |
cleanJiraMarkdownLink: () => | |
replaceTokens(/\[\[([^\]]+)\][^\]]*\]\(([^)]+)\)/, '[$1]($2)'), | |
commentBash: () => surroundWith('# '), | |
commentCss: () => surroundWith('/* ', ' */'), | |
commentDjango: () => surroundWith('{# ', ' #}'), | |
commentHtml: () => surroundWith('<!-- ', ' -->'), | |
curlyQuote: () => surroundWith('`', '`'), | |
doubleInsideSingle: () => [functions.doubleQuote, functions.singleQuote], | |
doubleQuote: () => surroundWith('"', '"'), | |
escapeSlashes: () => replaceTokens(/\//g, '\\/'), | |
filterWebConsole: () => surroundWith(`-\/`, `\/`).replace(/\s+/gm, '|'), | |
formatTextWidth50: () => formatTextWidth(50), | |
formatTextWidth72: () => formatTextWidth(72), | |
formatTextWidth80: () => formatTextWidth(80), | |
getTicketFromUrl: () => getClipboard().split('/').pop(), | |
jsDocQuerySelect: () => surroundWith('document.querySelector(`', '`)'), | |
jsDocQuerySelectAll: () => surroundWith('document.querySelectorAll(`', '`)'), | |
jsQuerySelect: () => surroundWith('querySelector(`', '`)'), | |
jsQuerySelectAll: () => surroundWith('querySelectorAll(`', '`)'), | |
keyValuePair: () => surroundWith(`'`, `': '',`), | |
localhostFrom127: () => replaceTokens('127.0.0.1', 'localhost'), | |
localhostFromZero: () => replaceTokens('0.0.0.0', 'localhost'), | |
localhostTo127: () => replaceTokens('localhost', '127.0.0.1'), | |
localhostToZero: () => replaceTokens('localhost', '0.0.0.0'), | |
markdownLinkFromTitle: () => surroundWith('[', '](URL)'), | |
markdownLinkFromURL: () => surroundWith('[TITLE](', ')'), | |
removeGitHubPrAuthor: () => replaceTokens(/(\[.*) by .*]/, '$1]'), | |
removeJiraSpam: () => replaceTokens(/(\[.*) - Jira.*]/, '$1]'), | |
removeNewline: () => replaceTokens(/(\r|\n|\s)+/gm, ' '), | |
removeSpaces: () => replaceTokens(/(\s)+/gm, ''), | |
replaceDashWithPeriod: () => replaceTokens(/-+/gm, '.'), | |
replaceDashWithSpace: () => replaceTokens(/-+/gm, ' '), | |
replaceDashWithUnderscore: () => replaceTokens(/-+/gm, '_'), | |
replaceSpaceWithDash: () => replaceTokens(/\s+/gm, '-'), | |
replaceSpaceWithPeriod: () => replaceTokens(/\s+/gm, '.'), | |
replaceSpaceWithUnderscore: () => replaceTokens(/\s+/gm, '_'), | |
replaceUnderscoreWithDash: () => replaceTokens(/_+/gm, '-'), | |
replaceUnderscoreWithPeriod: () => replaceTokens(/_+/gm, '.'), | |
replaceUnderscoreWithSpace: () => replaceTokens(/_+/gm, ' '), | |
reverseString: () => getClipboard().split('').reverse().join(''), | |
singleInsideDouble: () => [functions.singleQuote, functions.doubleQuote], | |
singleQuote: () => surroundWith(`'`, `'`), | |
splitAndCount4: () => | |
getClipboard() | |
.match(/.{1,4}/g) | |
.join('-') | |
.concat(` (${getClipboard().length})`), | |
toLowerCase: () => getClipboard().toLowerCase(), | |
toTitleCase: () => | |
replaceTokens(/\b\w/g, (match) => match.slice(-1).toUpperCase()), | |
toUpperCase: () => getClipboard().toUpperCase(), | |
trim: () => getClipboard().trim(), | |
uncommentCss: () => removeSurround(`\\/\\*`, `\\*\\/`), | |
uncommentDjango: () => removeSurround('{#', '#}'), | |
uncommentHtml: () => removeSurround('<!--', '-->'), | |
} | |
const aliases = { | |
case_SnakeToCamel: ['stc'], | |
caseCamelTo_Snake: ['cts'], | |
checkoutBranch: ['gcob'], | |
checkoutChoreBranch: ['gcho'], | |
checkoutFeatureBranch: ['gfea'], | |
checkoutFixBranch: ['gfix'], | |
cleanEncodedUrlTracking: ['ceut'], | |
cleanJiraMarkdownLink: ['cjml'], | |
commentBash: ['cbash'], | |
commentCss: ['ccss'], | |
commentDjango: ['cdjango'], | |
commentHtml: ['chtml'], | |
curlyQuote: ['cq'], | |
doubleInsideSingle: ['dqis'], | |
doubleQuote: ['dq'], | |
escapeSlashes: ['ep'], | |
filterWebConsole: ['fwc'], | |
formatTextWidth50: ['fw5', 'ftw50'], | |
formatTextWidth72: ['fw7', 'ftw72'], | |
formatTextWidth80: ['fw8', 'ftw80'], | |
keyValuePair: ['kvp'], | |
markdownLinkFromTitle: ['mdlft', 'mdlt'], | |
markdownLinkFromURL: ['mdlfu', 'mdlu'], | |
removeGitHubPrAuthor: ['rmghpa', 'rmgha'], | |
removeNewline: ['rmnl'], | |
reverseString: ['rev'], | |
singleInsideDouble: ['sid'], | |
singleQuote: ['s', 'sq'], | |
toLowerCase: ['tl', 'tlc', 'lc'], | |
toTitleCase: ['tt', 'ttc', 'tc'], | |
toUpperCase: ['tu', 'tuc', 'uc'], | |
trim: ['t'], | |
uncommentCss: ['uccss'], | |
uncommentDjango: ['ucdjango'], | |
uncommentHtml: ['uchtml'], | |
} | |
module.exports = { | |
aliases, | |
functions, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment