Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree: run shellharden on bash files #328

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dracula.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

$current_dir/scripts/dracula.sh
"$current_dir"/scripts/dracula.sh

6 changes: 3 additions & 3 deletions scripts/attached_clients.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export LC_ALL=en_US.UTF-8
# @dracula-clients-plural clients

current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh
source "$current_dir"/utils.sh

count_clients() {
pane=$(tmux list-panes -F "#{session_name}" | head -n 1)
tmux list-clients -t $pane | wc -l | tr -d ' '
tmux list-clients -t "$pane" | wc -l | tr -d ' '
}

main() {
Expand All @@ -28,7 +28,7 @@ main() {
fi
echo "$clients_count $clients_label"
fi
sleep $RATE
sleep "$RATE"
}

# run main driver
Expand Down
16 changes: 8 additions & 8 deletions scripts/battery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
export LC_ALL=en_US.UTF-8

current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
source "$current_dir"/utils.sh

linux_acpi() {
arg=$1
BAT=$(ls -d /sys/class/power_supply/*)
if [ ! -x "$(which acpi 2> /dev/null)" ];then
for DEV in $BAT; do
for DEV in "${BAT[@]}"; do
case "$arg" in
status)
[ -f "$DEV/status" ] && cat "$DEV/status"
Expand Down Expand Up @@ -41,15 +41,15 @@ battery_percent()
case $(uname -s) in
Linux)
percent=$(linux_acpi percent)
[ -n "$percent" ] && echo "$percent%"
[ "$percent" != "" ] && echo "$percent%"
;;

Darwin)
echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%')
echo "$(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%')"
;;

FreeBSD)
echo $(apm | sed '8,11d' | grep life | awk '{print $4}')
echo "$(apm | sed '8,11d' | grep life | awk '{print $4}')"
;;

CYGWIN*|MINGW32*|MSYS*|MINGW*)
Expand Down Expand Up @@ -161,17 +161,17 @@ main()
fi

show_bat_label=$(get_tmux_option "@dracula-show-battery-status" false)
if $show_bat_label; then
if "$show_bat_label"; then
bat_stat=$(battery_status)
else
bat_stat=""
fi

bat_perc=$(battery_percent)

if [ -z "$bat_stat" ]; then # Test if status is empty or not
if [ "$bat_stat" = "" ]; then # Test if status is empty or not
echo "$bat_label $bat_perc"
elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power
elif [ "$bat_perc" = "" ]; then # In case it is a desktop with no battery percent, only AC power
echo "$no_bat_label"
else
echo "$bat_label$bat_stat $bat_perc"
Expand Down
6 changes: 3 additions & 3 deletions scripts/continuum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ auto_save_interval_option="@continuum-save-interval"
auto_save_interval_default="15"

current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh
source "$current_dir"/utils.sh

current_timestamp() {
echo "$(date +%s)"
Expand Down Expand Up @@ -73,7 +73,7 @@ set_tmux_option() {

# tmux-resurrect dir
resurrect_dir() {
if [ -z "$_RESURRECT_DIR" ]; then
if [ "$_RESURRECT_DIR" = "" ]; then
local path="$(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")"
# expands tilde, $HOME and $HOSTNAME if used in @resurrect-dir
echo "$path" | sed "s,\$HOME,$HOME,g; s,\$HOSTNAME,$(hostname),g; s,\~,$HOME,g"
Expand All @@ -92,7 +92,7 @@ last_saved_timestamp() {
local first_save_timestamp="$(get_tmux_option "$first_save" "")"
# continuum sets the last save timestamp to the current time on first load if auto_save_option is not set
# so we can outrace it and detect that last_uato_save_option is empty and the timestamp is a dummy save
if [ -z "$first_save_timestamp" ]; then
if [ "$first_save_timestamp" = "" ]; then
last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=-1
set_tmux_option "$first_save" "$last_saved_timestamp"
elif [ "$first_save_timestamp" != "done" ]; then
Expand Down
12 changes: 6 additions & 6 deletions scripts/cpu_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
export LC_ALL=en_US.UTF-8

current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
source "$current_dir"/utils.sh

get_percent()
{
case $(uname -s) in
Linux)
percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -d 0.01 | grep "Cpu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
normalize_percent_len $percent
normalize_percent_len "$percent"
;;

Darwin)
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
cpucores=$(sysctl -n hw.logicalcpu)
cpuusage=$(( cpuvalue / cpucores ))
percent="$cpuusage%"
normalize_percent_len $percent
normalize_percent_len "$percent"
;;

OpenBSD)
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
cpucores=$(sysctl -n hw.ncpuonline)
cpuusage=$(( cpuvalue / cpucores ))
percent="$cpuusage%"
normalize_percent_len $percent
normalize_percent_len "$percent"
;;

CYGWIN*|MINGW32*|MSYS*|MINGW*)
Expand All @@ -39,7 +39,7 @@ get_load() {
case $(uname -s) in
Linux | Darwin | OpenBSD)
loadavg=$(uptime | awk -F'[a-z]:' '{ print $2}' | sed 's/,//g')
echo $loadavg
echo "$loadavg"
;;

CYGWIN* | MINGW32* | MSYS* | MINGW*)
Expand All @@ -59,7 +59,7 @@ main() {
cpu_percent=$(get_percent)
echo "$cpu_label $cpu_percent"
fi
sleep $RATE
sleep "$RATE"
}

# run main driver
Expand Down
4 changes: 2 additions & 2 deletions scripts/cwd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source "$current_dir/utils.sh"
getPaneDir() {
nextone="false"
ret=""
for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); do
for i in "$(tmux list-panes -F "#{pane_active} #{pane_current_path}")"; do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to break the scripts functionality

[ "$i" == "1" ] && nextone="true" && continue
[ "$i" == "0" ] && nextone="false"
[ "$nextone" == "true" ] && ret+="$i "
Expand Down Expand Up @@ -41,7 +41,7 @@ main() {
fi

cwd_max_chars="$(get_tmux_option "@dracula-cwd-max-chars" "0")"
if [[ "${cwd_max_chars}" -gt 0 && "${#cwd}" -gt "$cwd_max_chars" ]]; then
if [[ "$cwd_max_chars" -gt 0 && "${#cwd}" -gt "$cwd_max_chars" ]]; then
cwd="…/…${cwd:(- cwd_max_chars)}"
fi

Expand Down
Loading
Loading