Skip to content

Commit

Permalink
update: January 2024
Browse files Browse the repository at this point in the history
• Fixed nvim bootstrapping problem, added new keybinds & removed an unnecessary one
• Refactor & improve scripts
• A few changes in Ushiwaka theme
  • Loading branch information
SamIsTheFBI committed Jan 10, 2024
1 parent 79e7eac commit 6b546b5
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 92 deletions.
1 change: 1 addition & 0 deletions .config/nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('options')
require('plugins')
require('modules')
require('keymaps')
1 change: 0 additions & 1 deletion .config/nvim/lua/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ keymap("n", "<S-TAB>", ":bprevious<CR>", opts)
keymap("n", "<C-s>", ":retab<CR>:w<CR>", opts)

keymap("n", "<leader>e", ":NvimTreeFindFileToggle<cr>", opts)
keymap("n", "<leader>q", ":NvimTreeClose<cr>:wq!<cr>", opts)
keymap("n", "<leader>bd", ":bd<cr>", opts)
keymap("n", "<leader>gc", ":w<CR>:!gcc -o a % -lm<cr>", opts)
keymap("n", "<leader>gp", ":w<CR>:!g++ -std=gnu++20 -O2 -Wall % -o a<cr>", opts)
Expand Down
10 changes: 0 additions & 10 deletions .config/nvim/lua/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,4 @@ return require('packer').startup(function(use)
if PACKER_BOOTSTRAP then
require("packer").sync()
end

-- load modules
local modules = {
"coding",
"ricing",
}

for _, mod in ipairs(modules) do
require("" .. mod)
end
end)
1 change: 1 addition & 0 deletions .config/nvim/lua/ricing/whichkey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local mappings = {
w = { ":w!<CR>", "Save" },
h = { ":noh<CR>", "stop highlight" },
W = { ":wq<CR>", "Save & quit" },
gd = { ":Telescope lsp_definitions<CR>", "Go to definition" },
rn = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename occurrence" },
}
local opts = { prefix = '<leader>' }
Expand Down
4 changes: 2 additions & 2 deletions .config/nvim/plugin/packer_compiled.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ local function save_profiles(threshold)
end

time([[Luarocks path setup]], true)
local package_path_str = "/home/samisthefbi/.cache/nvim/packer_hererocks/2.1.1697887905/share/lua/5.1/?.lua;/home/samisthefbi/.cache/nvim/packer_hererocks/2.1.1697887905/share/lua/5.1/?/init.lua;/home/samisthefbi/.cache/nvim/packer_hererocks/2.1.1697887905/lib/luarocks/rocks-5.1/?.lua;/home/samisthefbi/.cache/nvim/packer_hererocks/2.1.1697887905/lib/luarocks/rocks-5.1/?/init.lua"
local install_cpath_pattern = "/home/samisthefbi/.cache/nvim/packer_hererocks/2.1.1697887905/lib/lua/5.1/?.so"
local package_path_str = "/home/samisthefbi/.cache/nvim/packer_hererocks/2.1.1702233742/share/lua/5.1/?.lua;/home/samisthefbi/.cache/nvim/packer_hererocks/2.1.1702233742/share/lua/5.1/?/init.lua;/home/samisthefbi/.cache/nvim/packer_hererocks/2.1.1702233742/lib/luarocks/rocks-5.1/?.lua;/home/samisthefbi/.cache/nvim/packer_hererocks/2.1.1702233742/lib/luarocks/rocks-5.1/?/init.lua"
local install_cpath_pattern = "/home/samisthefbi/.cache/nvim/packer_hererocks/2.1.1702233742/lib/lua/5.1/?.so"
if not string.find(package.path, package_path_str, 1, true) then
package.path = package.path .. ';' .. package_path_str
end
Expand Down
79 changes: 48 additions & 31 deletions .local/bin/gen-license
Original file line number Diff line number Diff line change
@@ -1,44 +1,61 @@
#!/bin/sh

GITHUB_LICENSE_API="https://api.github.com/licenses"
CACHE_DIR="${XDG_CACHE_HOME:-${HOME}/.cache}/license-generator"
github_license_api="https://api.github.com/licenses"
cache_dir="${XDG_CACHE_HOME:-${HOME}/.cache}/license-generator"

[ ! -d "${CACHE_DIR}" ] && mkdir -p "${CACHE_DIR}"
downloadFile() {
url="${1}"
dest="${2}"

if command -v curl >/dev/null 2>&1; then
curl -sS -L "${GITHUB_LICENSE_API}" --compressed > "${CACHE_DIR}/licenses.json"
else
wget -r "${GITHUB_LICENSE_API}" --tries=5 -O "${CACHE_DIR}/licenses.json"
fi
if command -v curl >/dev/null 2>&1; then
curl -sS -L "${url}" --compressed > "${dest}" \
|| { printf "%s" "Error: Failed to fetch data using curl."; exit 1; }
elif command -v wget >/dev/null 2>&1; then
wget -r "${url}" --tries=5 -O "${dest}" \
|| { printf "%s" "Error: Failed to fetch data using wget."; exit 1; }
elif command -v aria2c >/dev/null 2>&1; then
aria2c --allow-overwrite=true "${url}" -o "${dest}" \
|| { printf "%s" "Error: Failed to fetch data using aria2c."; exit 1; }
else
printf "%s" "Error: Neither curl nor wget nor aria2c is available. Install one of them."
exit 1
fi
}

jq -r '[.[] | select(.key) | .url]' "${CACHE_DIR}/licenses.json" | sed 's/\\//g' | sed '1d' | sed '$d' | sed 's/,//g' | sed 's/"//g' | sed 's/^[ \t]*//' > "${CACHE_DIR}/LICENSE_URLS"
[ "$(command -v fzf)" ] \
|| { printf "%s" "Error: fzf is required for this script. Install it first."; exit 1; }

jq -r '[.[] | select(.key) | .name]' "${CACHE_DIR}/licenses.json" | sed 's/\\//g' | sed 's/^[ \t]*//' | sed '1d' | sed '$d' | sed 's/"//' | sed 's/.$//' | sed 's/"$//' > "${CACHE_DIR}/LICENSE_NAMES"
mkdir -p "${cache_dir}"

NAME=$(grep '' "${CACHE_DIR}/LICENSE_NAMES" | fzf --prompt "> Choose a license: " --height 40% --reverse)
[ -z "${NAME}" ] && exit
echo -e "Choose a license: ${NAME}"
downloadFile "${github_license_api}" "${cache_dir}/licenses.json"

N=$(grep -n "${NAME}" "${CACHE_DIR}/LICENSE_NAMES" | cut -d ":" -f1)
jq -r '.[] | select(.key) | .url' "${cache_dir}/licenses.json" \
> "${cache_dir}/license_urls"

LICENSE_URL="$(sed -n "${N}p" "${CACHE_DIR}/LICENSE_URLS")"
LICENSE_NAME="$(echo -e "${LICENSE_URL}" | cut -d "/" -f5)"
jq -r '.[] | select(.key) | .name' "${cache_dir}/licenses.json" \
> "${cache_dir}/license_names"

if command -v curl >/dev/null 2>&1; then
curl -sS -L "${LICENSE_URL}" --compressed > "${CACHE_DIR}/${LICENSE_NAME}.json"
else
wget -r "${LICENSE_URL}" --tries=5 -O "${CACHE_DIR}/${LICENSE_NAME}.json"
fi
chosen_license=$(grep '' "${cache_dir}/license_names" \
| fzf --prompt "> Choose a license: " --height 40% --reverse)

echo -n "Enter your name: "
read FN
FULLNAME="${FN}"
[ "${chosen_license}" ] || exit 1
printf "%s" "Choose a license: ${chosen_license}"

echo -n "Enter year: "
read FN
[ -z "${FN}" ] && FN="$(date '+%Y')"
YEAR="${FN}"
line_number=$(grep -n "${chosen_license}" "${cache_dir}/license_names" \
| cut -d ":" -f1)

jq -r '.body' "${CACHE_DIR}/${LICENSE_NAME}.json" |
sed "s/\[fullname\]/${FULLNAME}/g" |
sed "s/\[year\]/${YEAR}/g" > LICENSE
license_url="$(sed -n "${line_number}p" "${cache_dir}/license_urls")"
license_name="$(printf "%s" "${license_url}" | cut -d "/" -f5)"

downloadFile "${license_url}" "${cache_dir}/${license_name}.json"

printf "\n%s" "Enter your name: "
read -r fullname

printf "%s" "Enter year: "
read -r year
[ "${year}" ] || year="$(date '+%Y')"

jq -r '.body' "${cache_dir}/${license_name}.json" \
| sed "s/\[fullname\]/${fullname}/g" \
| sed "s/\[year\]/${year}/g" > LICENSE
16 changes: 8 additions & 8 deletions .local/bin/screencap
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
# Dependencies: maim | imagemagick

prompt='dmenu -i -h 30 -y 5 -p'
SCREENSHOT="maim"
screenshot="maim"
[ "$(pgrep -x picom)" ] \
&& SELECTSHOT="maim -s -u -b 2 -c 0.35,0.55,0.85,0.25 -l" \
|| SELECTSHOT="maim -s -u -b 2 -c 0.35,0.55,0.85,0.25"
SCR_DIR="${HOME}/Screenshots"
[ ! -d "${SCR_DIR}" ] && mkdir "${SCR_DIR}"

#SCREENSHOT="import -window root"
#screenshot="import -window root"
# SELECTSHOT="import" # Freezes the screen when taking screenshot

if [ -z "$1" ];then
${SCREENSHOT} ~/.cache/cache.png
${screenshot} ~/.cache/cache.png
xclip -selection clipboard -t image/png ~/.cache/cache.png
notify-send -i "~/.cache/cache.png" ' Screenshot' '<span font="JetBrainsMono Nerd Font 11">  Copied to clipboard</span>'
notify-send -i "~/.cache/cache.png" '󰊓 Screenshot' '<span font="JetBrainsMono Nerd Font 11">  Copied to clipboard</span>'
elif [ "$1" == "fullsave" ];then
var="${SCR_DIR}"/Screenshot_$(date +%Y%m%d_%H%M%S).png
${SCREENSHOT} $var
${screenshot} $var
xclip -selection clipboard -t image/png $var
notify-send -i "$var" ' Screenshot' '<span font="JetBrainsMono Nerd Font 11">  Saved & copied to clipboard</span>'
notify-send -i "$var" '󰊓 Screenshot' '<span font="JetBrainsMono Nerd Font 11">  Saved & copied to clipboard</span>'
elif [ "$1" == "selectcopy" ];then
var="${SCR_DIR}"/ScreenSelect_$(date +%Y%m%d_%H%M%S).png
${SELECTSHOT} ~/.cache/cache.png
Expand All @@ -46,12 +46,12 @@ elif [ "$1" == "selectsave" ];then
xclip -selection clipboard -t image/png $var
notify-send -i "$var" '里 Screen Selection' '<span font="JetBrainsMono Nerd Font 11">  Saved & copied to clipboard</span>'
elif [ "$1" == "actwincopy" ];then
${SCREENSHOT} $(xdotool getactivewindow) ~/.cache/cache.png
${screenshot} $(xdotool getactivewindow) ~/.cache/cache.png
xclip -selection clipboard -t image/png ~/.cache/cache.png
notify-send -i "~/.cache/cache.png" ' Active Window Screenshot' '<span font="JetBrainsMono Nerd Font 11">  Copied to clipboard</span>'
elif [ "$1" == "actwinsave" ];then
var="${SCR_DIR}"/$(xdotool getactivewindow getwindowclassname)_$(date +%Y%m%d_%H%M%S).png
${SCREENSHOT} $(xdotool getactivewindow) $var
${screenshot} $(xdotool getactivewindow) $var
xclip -selection clipboard -t image/png $var
notify-send -i "$var" ' Active Window Screenshot' '<span font="JetBrainsMono Nerd Font 11">  Saved & copied to clipboard</span>'
fi
32 changes: 16 additions & 16 deletions .local/bin/update-arch
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
#!/bin/sh

PKG="${XDG_CONFIG_HOME:-${HOME}/.config}/update-arch/packages.txt"
RETRY="${XDG_CONFIG_HOME:-${HOME}/.config}/update-arch/retry.txt"
DED="${XDG_CONFIG_HOME:-${HOME}/.config}/update-arch/problem-packages.txt"
pkgs="${XDG_CONFIG_HOME:-${HOME}/.config}/update-arch/packages.txt"
retry_pkgs="${XDG_CONFIG_HOME:-${HOME}/.config}/update-arch/retry.txt"
ded_pkgs="${XDG_CONFIG_HOME:-${HOME}/.config}/update-arch/problem-packages.txt"

rm -rf "${PKG}" "${RETRY}" "${DED}"
rm -rf "${pkgs}" "${retry_pkgs}" "${ded_pkgs}"
space_left=$(df /home/ --output=avail | grep "[0-9]")

[ ${space_left} == 0 ] && echo -e "No space available for update!" && exit

[ ! -d "${XDG_CONFIG_HOME:-${HOME}/.config}/update-arch" ] && mkdir -p "${XDG_CONFIG_HOME:-${HOME}/.config}/update-arch"
pacman -Qu | awk -F ' ' '{print $1}' >> "${PKG}"
pacman -Qu | awk -F ' ' '{print $1}' >> "${pkgs}"

# echo "Please write your password. It will be needed to run sudo to update your system"
# read password
echo ${password} | sudo pacman -Sy --noconfirm --needed archlinux-keyring

pages=1
while [[ ${pages} != 0 && ${space_left} != 0 ]]; do
echo ${password} | sudo pacman -Sy --noconfirm --needed $(cat "${PKG}" | sed -n 1p)
[ $(echo $?) != 0 ] && echo -e $(cat "${PKG}" | sed -n 1p) >> "${RETRY}"
sed -i '1d' "${PKG}"
pages=$(cat "${PKG}" | wc -l)
echo ${password} | sudo pacman -Sy --noconfirm --needed $(cat "${pkgs}" | sed -n 1p)
[ $(echo $?) != 0 ] && echo -e $(cat "${pkgs}" | sed -n 1p) >> "${retry_pkgs}"
sed -i '1d' "${pkgs}"
pages=$(cat "${pkgs}" | wc -l)
space_left=$(df /home/ --output=avail | grep "[0-9]")
done

[ ${space_left} == 0 ] && echo -e "No space available for update!" && exit

pages=$(cat "${RETRY}" | wc -l)
pages=$(cat "${retry_pkgs}" | wc -l)
while [[ ${pages} != 0 && ${space_left} != 0 ]]; do
echo ${password} | sudo pacman -Sy --noconfirm --needed $(cat "${RETRY}" | sed -n 1p)
[ $(echo $?) != 0 ] && echo -e $(cat "${RETRY}" | sed -n 1p) >> "${DED}"
sed -i '1d' "${RETRY}"
pages=$(cat "${RETRY}" | wc -l)
echo ${password} | sudo pacman -Sy --noconfirm --needed $(cat "${retry_pkgs}" | sed -n 1p)
[ $(echo $?) != 0 ] && echo -e $(cat "${retry_pkgs}" | sed -n 1p) >> "${ded_pkgs}"
sed -i '1d' "${retry_pkgs}"
pages=$(cat "${retry_pkgs}" | wc -l)
space_left=$(df /home/ --output=avail | grep "[0-9]")
done

[ ${space_left} == 0 ] && echo -e "No space available for update!" && exit

pages=$(cat "${DED}" | wc -l)
pages=$(cat "${ded_pkgs}" | wc -l)
if [ ${pages} != 0 ]; then
echo -e "Some packages were not updated due to some issues. Please check ${DED}. You may download & install them manually"
echo -e "Some packages were not updated due to some issues. Please check ${ded_pkgs}. You may download & install them manually"
fi
Loading

0 comments on commit 6b546b5

Please sign in to comment.