- Shell Scripts: FZF function to fuzzy find all of my projects and open nvim on that project

- Shell Scripts: WIP efforts to comply all to POSIX
This commit is contained in:
Pratik Tripathy
2024-02-06 23:17:01 +05:30
parent 5fa524dd1d
commit 6b2d076cdc
10 changed files with 146 additions and 2636 deletions

View File

@@ -1,5 +1,9 @@
#!/bin/sh
#
# TODO: Use this to better manage dotfiles
# https://github.com/dylanirlbeck/dotfiles/blob/master/scripts/bootstrap.sh
##################################
# Parse script arguments
##################################
@@ -8,29 +12,6 @@
QUIET="n"
CREATE_LINKS="n"
while [[ "${#}" -gt 0 ]]; do
case $1 in
-q | --quiet)
QUIET="y"
shift
;;
-l | --create-links)
CREATE_LINKS="y"
shift
;;
-h | --help)
echo
usage
echo
exit 0
;;
*)
usage "Unknown parameter passed: $1" "h"
exit 1
;;
esac
done
usage() {
if [ -n "$1" ]; then
echo ""
@@ -57,32 +38,61 @@ place_dotfile_at_target_location() {
# To avoid over writing existing dot file, we rename them
# Appending the timestamp to file name
if [[ -f "${file_target_location}" || -L "${file_target_location}" ]]; then
if [ -f "${file_target_location}" ] || [ -L "${file_target_location}" ]; then
# echo "mv ${file_target_location} ${file_target_location}_${TS}" && [[ "$QUIET" == "n" ]] && echo "Existing dotfile renamed to ${file_target_location}_${TS}"
mv "${file_target_location}" "${file_target_location}_${TS}" && [[ "$QUIET" == "n" ]] && echo "Existing setting renamed to ${file_target_location}_${TS}"
mv "${file_target_location}" "${file_target_location}_${TS}" && [ "$QUIET" = "n" ] && echo "Existing setting renamed to ${file_target_location}_${TS}"
fi
local target_directory
target_directory=$(dirname "${file_target_location}")
if [[ ! -d "${target_directory}" ]]; then
mkdir -p "${target_directory}" && [[ "$QUIET" == "n" ]] && echo "Directory ${target_directory} created"
if [ ! -d "${target_directory}" ]; then
mkdir -p "${target_directory}" && [ "$QUIET" = "n" ] && echo "Directory ${target_directory} created"
fi
if [[ "$CREATE_LINKS" == "y" ]]; then
if [ "$CREATE_LINKS" = "y" ]; then
# echo "ln -s ${source_file_location} ${target_directory}"
ln -s "${source_file_location}" "${target_directory}" && [[ "$QUIET" == "n" ]] && echo "Linked ${file_target_location}"
ln -s "${source_file_location}" "${target_directory}" && [ "$QUIET" = "n" ] && echo "Linked ${file_target_location}"
else
# echo "cp ${source_file_location} ${target_directory}"
cp "${source_file_location}" "${target_directory}" && [[ "$QUIET" == "n" ]] && echo "Copied ${file_target_location}"
cp "${source_file_location}" "${target_directory}" && [ "$QUIET" = "n" ] && echo "Copied ${file_target_location}"
fi
}
main() {
if [[ $(uname -s) == *Darwin* ]]; then
OS="macos"
else
OS="kde-neon"
fi
while [ "${#}" -gt 0 ]; do
case $1 in
-q | --quiet)
QUIET="y"
shift
;;
-l | --create-links)
CREATE_LINKS="y"
shift
;;
-h | --help)
echo
usage
echo
exit 0
;;
*)
usage "Unknown parameter passed: $1" "h"
exit 1
;;
esac
done
case $(uname -a) in
Linux*)
OS="linux"
[ "$XDG_CURRENT_DESKTOP" = "KDE" ] && OS="kde-neon"
;;
Darwin*)
OS="macos"
;;
*)
OS="UNSUPPORTED"
esac
TS=$(date '+%d_%m_%Y-%H_%M_%S')
@@ -91,19 +101,19 @@ main() {
# Copy all files in "Common" dotfiles to $HOME directory ("~")
find "./common" -type f ! -path '*.DS_Store' ! -path '*.directory' -print0 | while IFS= read -r -d '' file;
do
local file_target_location="${file/.\/common/$HOME}"
local source_file_location="${file/./$PWD}"
place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS"
done
do
local file_target_location="${file/.\/common/$HOME}"
local source_file_location="${file/./$PWD}"
place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS"
done
# Copy platform specific files to $HOME directory ("~")
find "./${OS}" -type f ! -path '*.DS_Store' ! -path '*.directory' -print0 | while IFS= read -r -d '' file;
do
local file_target_location="${file/.\/${OS}/$HOME}"
local source_file_location="${file/./$PWD}"
place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS"
done
do
local file_target_location="${file/.\/${OS}/$HOME}"
local source_file_location="${file/./$PWD}"
place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS"
done
}
main "$@"