Skip to content

Commit

Permalink
Fixing some zsh functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardolm committed Nov 24, 2023
1 parent a9e94f6 commit f09f956
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 62 deletions.
6 changes: 6 additions & 0 deletions zsh/functions/auto-ls-custom_function
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env zsh

function auto-ls-custom_function() {
echo -e "\nauto-ls-custom_function:\n"
exa -GxFa --icons --group-directories-first --no-filesize --no-user
}
2 changes: 1 addition & 1 deletion zsh/functions/caller
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ function caller() {
fi
done

printf "${_stack}${_reset_color}"
printf " ${_stack}${_reset_color}"
fi
}
29 changes: 17 additions & 12 deletions zsh/functions/chmod_reset
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
#!/usr/bin/env zsh

function chmod_reset() {
[ -z "$1" ] && echo "path is required" && \
return 1 || \
log start "resetting permissions on '$1'... "
# shell_debug_relay=$SHELL_DEBUG
# SHELL_DEBUG=true

/usr/bin/sudo chown -R "$USER:$USER" "$1"
/usr/bin/sudo chmod -R 644 "$1"
/usr/bin/sudo find "$1" -type d -exec chmod +x {} \;
$SHELL_DEBUG && set -x

sudo chmod -cR 600 $1
sudo chmod -R u+X $1
sudo chown -cR $USER:$USER $1

patterns=(
"*.AppImage"
"*.py"
"*.sh"
"setup"
"start"
"install"
"pre-install"
"/bin/"
"install-pristine"
"install"
"post-install"
"post-setup"
"pre-install"
"pre-setup"
"setup"
"start"
)
for p in "${patterns[@]}"; do
find "$1" -name "$p" -exec chmod +x {} \;
sudo find "$1" -name "$p" -exec sudo chmod u+x {} \;
done

echo "done"
# SHELL_DEBUG=$shell_debug_relay
$SHELL_DEBUG && set +x
}
2 changes: 1 addition & 1 deletion zsh/functions/db_migrate
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env zsh

function db_migrate () {
function db_migrate() {
DOCKER_IMAGE_NAME=renatovico/simple-db-migrate
docker build https://raw.githubusercontent.com/renatovico/simple-db-migrate-docker/master/Dockerfile -t ${DOCKER_IMAGE_NAME}:latest
echo "params to use in database ${1}:"
Expand Down
4 changes: 2 additions & 2 deletions zsh/functions/dropbox_sync
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ function dropbox_sync() {
echo -e "running dropbox-worker..."
notify-send "dropbox-worker" "running..."

dropbox start
dropbox.py start

echo -e "giving $wait_for to dropbox work..."
sleep $wait_for

dropbox stop
dropbox.py stop

echo -e "finish dropbox-worker"
notify-send "dropbox-worker" "finish"
Expand Down
2 changes: 1 addition & 1 deletion zsh/functions/emoji_random
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env zsh

function emoji_random () {
function emoji_random() {
local SELECTED_EMOJIS=(
💩
🐦
Expand Down
2 changes: 1 addition & 1 deletion zsh/functions/extract
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Note: .dmg/hdiutil is macOS-specific.
#
# credit: http://nparikh.org/notes/zshrc.txt
function extract () {
function extract() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar -jxvf $1 ;;
Expand Down
4 changes: 2 additions & 2 deletions zsh/functions/iterate_and_load
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ function iterate_and_load() {

local cmd="find $find_path -name '$find_term' -print 2>/dev/null | $filter_fn"

log_debug "$cmd"
log debug "$cmd"

eval "$cmd" | while read -r script_file; do
log_debug "$script_file"
log debug "$script_file"
# shellcheck source=/dev/null
. "$script_file"
done
Expand Down
23 changes: 12 additions & 11 deletions zsh/functions/log
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/usr/bin/env zsh

# shellcheck source=/dev/null
. "${DOTFILES}/zsh/init/20_colors.zsh"

function log() {
level=$1

silenced_levels=("debug" "start" "finish")

if ! $SHELL_DEBUG; then
if [[ ${silenced_levels[@]} =~ $level ]]; then
return
fi
fi

shift
. "${DOTFILES}/zsh/functions/log_debug"
. "${DOTFILES}/zsh/functions/log_echo"
. "${DOTFILES}/zsh/functions/log_error"
. "${DOTFILES}/zsh/functions/log_finish"
. "${DOTFILES}/zsh/functions/log_info"
. "${DOTFILES}/zsh/functions/log_is_command_success"
. "${DOTFILES}/zsh/functions/log_start"
. "${DOTFILES}/zsh/functions/log_warn"

. "${DOTFILES}/zsh/functions/caller"

eval "log_$level '$@'"
}
2 changes: 1 addition & 1 deletion zsh/functions/log_debug
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env zsh

function log_debug() {
log_echo "🐞" "${GREY}" "$@"
log_echo "🐞 ${GREY} $@ ${NC}"
}
27 changes: 8 additions & 19 deletions zsh/functions/log_echo
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
#!/usr/bin/env zsh

function log_echo() {
$SHELL_DEBUG || return
local fn_called
fn_called="$0"

local shell
shell="$0"

local icon
icon="$1"

shift

local color
color="$1"

shift

[ -n "$icon" ] && icon="$icon "
local msg
msg="$1"

local loutput=0
local lcaller=0
Expand All @@ -28,7 +17,7 @@ function log_echo() {

$SHELL_TRACE && _caller=$(caller)

local output="${icon}${color} $@ ${NC}"
local output=$msg

if ! command -v ansi2txt &>/dev/null; then
echo -e "${RED} you need to install colorized-logs package: ${NC}"
Expand All @@ -39,16 +28,16 @@ function log_echo() {
fi

if [[ $cols -ge 80 ]]; then
loutput=$(echo "${output}" | ansi2txt | wc -L)
loutput=$(echo " +++ ${output}" | ansi2txt | wc -L)

if [[ $loutput -gt $cols ]]; then
loutput=$(($loutput-$cols))
fi

rpad=$(($cols-$loutput))
lcaller=$(echo "${_caller}" | ansi2txt | wc -L)
lcaller=$(echo " --- ${_caller}" | ansi2txt | wc -L)
rpad=$(($rpad-$lcaller))
if [[ "$shell" =~ "zsh" ]]; then
if [[ "$fn_called" =~ "zsh" ]]; then
space=${(l:$rpad:: :)}
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion zsh/functions/log_error
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env zsh

function log_error() {
log_echo "💣" "$RED" "$@"
log_echo "💣 ${RED} $@ ${NC}"
}
2 changes: 1 addition & 1 deletion zsh/functions/log_finish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env zsh

function log_finish() {
log_echo "🛑" "$PURPLE" "$@" "was finished ⏱️ $(date +"%H:%M:%S.%3N")"
log_echo "🛑 $@ was finished at $(date +"%H:%M:%S.%3N") ⏱️ "
}
2 changes: 1 addition & 1 deletion zsh/functions/log_info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env zsh

function log_info() {
log_echo "💬" "$CYAN" "$@"
log_echo "💬 ${CYAN} $@ ${NC}"
}
2 changes: 1 addition & 1 deletion zsh/functions/log_start
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env zsh

function log_start() {
log_echo "🚦" "$PURPLE" "starting $@... ⏱️ $(date +"%H:%M:%S.%3N")"
log_echo " 🚦 starting $@ at $(date +"%H:%M:%S.%3N") ⏱️ "
}
2 changes: 1 addition & 1 deletion zsh/functions/log_warn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env zsh

function log_warn() {
log_echo "🚧" "$YELLOW" "$@"
log_echo "🚧 ${YELLOW} $@ ${NC}"
}
2 changes: 1 addition & 1 deletion zsh/functions/ls_2_exa
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ function ls_2_exa() {
command -v exa &> /dev/null || sudo apt-get install exa
args="$@"
args=$(echo $args | sed 's/A/a/g')
eval "exa $args"
eval "/usr/bin/exa --all --oneline --long --classify --icons --color always --group-directories-first --header --octal-permissions $args"
}
2 changes: 1 addition & 1 deletion zsh/functions/sudo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function sudo() {
"$@"
else
if ! env sudo --non-interactive true 2>/dev/null; then
log_warn "Root privileges are being requested. Pay attention to what you are doing!"
log warn "root privileges are being requested. pay attention to what you are doing!"
env sudo --validate
fi
env sudo "$@"
Expand Down
9 changes: 6 additions & 3 deletions zsh/functions/zsh_plugins_install
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env zsh

function zsh_plugins_install() {
shell_debug_relay=$SHELL_DEBUG
echo "zsh_plugins_install is DEPRECATED, using zplug"
return

# shell_debug_relay=$SHELL_DEBUG
# SHELL_DEBUG=true

local _zsh_plugins_list=($(zsh_plugins_list))
Expand All @@ -18,8 +21,8 @@ function zsh_plugins_install() {
else
output+="already installed"
fi
log_info "$output"
log info "$output"
done

SHELL_DEBUG=$shell_debug_relay
# SHELL_DEBUG=$shell_debug_relay
}
5 changes: 4 additions & 1 deletion zsh/functions/zsh_plugins_load
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env zsh

function zsh_plugins_load() {
echo "zsh_plugins_load is DEPRECATED, using zplug"
return

log start "zsh_plugins_load()"

plugins_path="${ZSH_CUSTOM}/plugins"

find "$plugins_path" -mindepth 3 -maxdepth 3 -name "*.plugin.zsh" | while read -r item; do
log_debug $item
log debug $item
. "$item"
done
}

0 comments on commit f09f956

Please sign in to comment.