Skip to content

Commit

Permalink
Add script 'List symbolic links'
Browse files Browse the repository at this point in the history
  • Loading branch information
cfgnunes committed Dec 12, 2024
1 parent 87328dc commit b81fe3a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Directories and files/Open item location
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ _main() {
input_files=$(_get_files "par_type=all; par_max_items=20; par_get_pwd=true")

# Run the main process.
_open_items_locations "$input_files"
_open_items_locations "$input_files" "true"
}

_main "$@"
2 changes: 1 addition & 1 deletion Link operations/List broken links
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _main() {

std_output=$(_text_remove_pwd "$std_output")

_display_list_box "$std_output" "--column=Link" "broken links"
_display_list_box "$std_output" "--column=Link" "broken links" "false"
}

_main "$@"
26 changes: 26 additions & 0 deletions Link operations/List symbolic links
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# Source the script 'common-functions.sh'.
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
source "$ROOT_DIR/common-functions.sh"

_main() {
local input_files=""
local std_output=""

# Execute initial checks.
_check_dependencies ""
_display_wait_box "2"
input_files=$(_get_files "par_type=all; par_get_pwd=true")

# Run the main process.
# shellcheck disable=SC2086
std_output=$(find $input_files -type l)

std_output=$(_text_remove_pwd "$std_output")

_display_list_box "$std_output" "--column=Link" "symbolic links" "false"
}

_main "$@"
15 changes: 12 additions & 3 deletions common-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,15 @@ _display_list_box() {
# format "--column=<name>;--column=<name>".
# - $3 (item_name): A string representing the name of the items in the
# list. If not provided, the default value is "items".
# - $4 (resolve_links): A boolean-like string ("true" or "false")
# indicating whether symbolic links in item paths should be resolved to
# their target locations when opening the item's location. Defaults to
# "true".

local message=$1
local columns=$2
local item_name=${3:-"items"}
local resolve_links=${4:-"true"}
local columns_count=0
local items_count=0
local selected_item=""
Expand Down Expand Up @@ -376,7 +381,7 @@ _display_list_box() {

if ((items_count != 0)) && [[ -n "$selected_item" ]]; then
# Open the directory of the clicked item in the list.
_open_items_locations "$selected_item"
_open_items_locations "$selected_item" "$resolve_links"
fi
elif _command_exists "kdialog"; then
columns=$(sed "s|--column=||g" <<<"$columns")
Expand Down Expand Up @@ -1382,8 +1387,12 @@ _open_items_locations() {
# Parameters:
# - $1: (items): A space-separated list of file or directory paths whose
# locations will be opened. Paths can be relative or absolute.
# - $2: (resolve_links): A boolean-like string ("true" or "false")
# indicating whether symbolic links in the provided paths should be
# resolved to their target locations before opening.

local items=$1
local resolve_links=$2
local dir=""

if [[ -z "$items" ]]; then
Expand Down Expand Up @@ -1416,7 +1425,7 @@ _open_items_locations() {
continue
fi

if [[ -L "$item" ]] && [[ -e "$item" ]]; then
if [[ "$resolve_links" == "true" ]] && [[ -L "$item" ]]; then
item=$(readlink -f "$item")
fi
items_open+="$item$FIELD_SEPARATOR"
Expand Down Expand Up @@ -1925,7 +1934,7 @@ _validate_file_mime() {
# MIME type pattern.
#
# Parameters:
# - $1 (input_file): The path to the file that is being validated. This
# - $1 (input_file): The path to the file that is being validated. This
# is the file whose MIME type will be checked.
# - $2 (par_select_mime): The MIME type pattern (or regular expression)
# to compare the file's MIME type against. If no MIME type pattern is
Expand Down

0 comments on commit b81fe3a

Please sign in to comment.