mirror of
https://github.com/chenasraf/dotfiles.git
synced 2026-05-18 01:29:06 +00:00
fix: text transform, pnpm install
This commit is contained in:
@@ -2,26 +2,31 @@ local function into_words(str)
|
||||
local words = {}
|
||||
local word = ""
|
||||
|
||||
local previous_is_upper = false
|
||||
for i = 1, #str do
|
||||
local char = str:sub(i, i)
|
||||
-- split on uppercase letters
|
||||
if char:match("%u") then
|
||||
if char:match("%u") and not previous_is_upper then
|
||||
if word ~= "" then
|
||||
table.insert(words, word)
|
||||
end
|
||||
previous_is_upper = true
|
||||
word = char
|
||||
-- split on underscores, hyphens, and spaces
|
||||
elseif char:match("[%_%-%s]") then
|
||||
if word ~= "" then
|
||||
table.insert(words, word)
|
||||
previous_is_upper = false
|
||||
end
|
||||
word = ""
|
||||
else
|
||||
word = word .. char
|
||||
previous_is_upper = char:match("%u")
|
||||
end
|
||||
end
|
||||
if word ~= "" then
|
||||
table.insert(words, word)
|
||||
previous_is_upper = false
|
||||
end
|
||||
return words
|
||||
end
|
||||
@@ -33,9 +38,9 @@ function CamelCase(string)
|
||||
local camel_case = ""
|
||||
for i, word in ipairs(words) do
|
||||
if i == 1 then
|
||||
camel_case = camel_case .. word
|
||||
camel_case = camel_case .. word:lower()
|
||||
else
|
||||
camel_case = camel_case .. word:gsub("^%l", string.upper)
|
||||
camel_case = camel_case .. word:sub(1, 1):upper() .. word:sub(2):lower()
|
||||
end
|
||||
end
|
||||
return camel_case
|
||||
@@ -58,7 +63,7 @@ function PascalCase(string)
|
||||
local words = into_words(string)
|
||||
local pascal_case = ""
|
||||
for _, word in ipairs(words) do
|
||||
pascal_case = pascal_case .. word:gsub("^%l", string.upper)
|
||||
pascal_case = pascal_case .. word:sub(1, 1):upper() .. word:sub(2):lower()
|
||||
end
|
||||
return pascal_case
|
||||
end
|
||||
@@ -93,7 +98,7 @@ function TitleCase(string)
|
||||
local words = into_words(string)
|
||||
local title_case = ""
|
||||
for i, word in ipairs(words) do
|
||||
title_case = title_case .. word:gsub("^%l", string.upper)
|
||||
title_case = title_case .. word:sub(1, 1):upper() .. word:sub(2):lower()
|
||||
if i ~= #words then
|
||||
title_case = title_case .. " "
|
||||
end
|
||||
@@ -113,6 +118,25 @@ function ReplaceCurrentWord(transform)
|
||||
vim.cmd("normal ciw" .. transformed)
|
||||
end
|
||||
|
||||
local should_test = false
|
||||
|
||||
if should_test then
|
||||
local map = {
|
||||
["CamelCase"] = CamelCase,
|
||||
["SnakeCase"] = SnakeCase,
|
||||
["PascalCase"] = PascalCase,
|
||||
["KebabCase"] = KebabCase,
|
||||
["DotCase"] = DotCase,
|
||||
["TitleCase"] = TitleCase,
|
||||
}
|
||||
|
||||
for k, tst in pairs(map) do
|
||||
print(k .. ": " .. "hello_world" .. " => " .. tst("hello_world"))
|
||||
print(k .. ": " .. "HELLO_WORLD" .. " => " .. tst("HELLO_WORLD"))
|
||||
print(k .. ": " .. "HelloWorld" .. " => " .. tst("HelloWorld"))
|
||||
print(k .. ": " .. "Hello-World" .. " => " .. tst("Hello-World"))
|
||||
end
|
||||
end
|
||||
-- use input from current word in editor
|
||||
vim.cmd('amenu Transforms.&camelCase :lua ReplaceCurrentWord(CamelCase)<CR>')
|
||||
vim.cmd('amenu Transforms.&snake_case :lua ReplaceCurrentWord(SnakeCase)<CR>')
|
||||
@@ -121,4 +145,4 @@ vim.cmd('amenu Transforms.&kebab-case :lua ReplaceCurrentWord(KebabCase)<CR>')
|
||||
vim.cmd('amenu Transforms.&dot\\.case :lua ReplaceCurrentWord(DotCase)<CR>')
|
||||
vim.cmd('amenu Transforms.&Title\\ Case :lua ReplaceCurrentWord(TitleCase)<CR>')
|
||||
|
||||
vim.keymap.set({"n", "v"}, "<leader>~", "<cmd>popup Transforms<CR>", { silent = true })
|
||||
vim.keymap.set({ "n", "v" }, "<leader>~", "<cmd>popup Transforms<CR>", { silent = true })
|
||||
|
||||
1
.zshrc
1
.zshrc
@@ -1,6 +1,7 @@
|
||||
export DOTFILES="$HOME/.dotfiles"
|
||||
export CFG="$DOTFILES/.config"
|
||||
export DOTBIN="$CFG/bin"
|
||||
git config --global core.excludesfile ~/.gitignore
|
||||
|
||||
# echo 'Loading '$DOTFILES/functions.sh
|
||||
source $DOTFILES/functions.sh
|
||||
|
||||
11
exports.sh
11
exports.sh
@@ -32,10 +32,13 @@ export PATH="$HOME/bin:/usr/local/bin:$PATH"
|
||||
# export PATH="$HOME/.gem/ruby/3.0.0/bin:$PATH"
|
||||
export PATH="$PATH:/$HOME/.local/bin"
|
||||
|
||||
# guile (?)
|
||||
# export GUILE_LOAD_PATH="/usr/local/share/guile/site/3.0"
|
||||
# export GUILE_LOAD_COMPILED_PATH="/usr/local/lib/guile/3.0/site-ccache"
|
||||
# export GUILE_SYSTEM_EXTENSIONS_PATH="/usr/local/lib/guile/3.0/extensions"
|
||||
# pnpm start
|
||||
export PNPM_HOME="$HOME/Library/pnpm"
|
||||
case ":$PATH:" in
|
||||
*":$PNPM_HOME:"*) ;;
|
||||
*) export PATH="$PNPM_HOME:$PATH" ;;
|
||||
esac
|
||||
# pnpm end
|
||||
|
||||
# yamllint
|
||||
export YAMLLINT_CONFIG_FILE="$HOME/.config/.yamllint.yml"
|
||||
|
||||
Reference in New Issue
Block a user