-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discussion: - https://github.com/bevry/dorothy/discussions/118 Closes: - #120 - #7 Most of the work done in: - de2170e
- Loading branch information
Showing
338 changed files
with
23,209 additions
and
15,016 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Autoformatter friendly flake8 config (all formatting rules disabled) | ||
[flake8] | ||
extend-ignore = E1, E2, E3, E501, W1, W2, W3, W5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: dorothy | ||
"on": | ||
- push | ||
- pull_request | ||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v2 | ||
- name: "Configure" | ||
shell: 'script -q -e -c "bash {0}"' | ||
run: | | ||
chmod +x ./commands/* | ||
./commands/dorothy dev | ||
- name: "Test" | ||
shell: 'script -q -e -c "bash {0}"' | ||
run: | | ||
./commands/dorothy test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# generic | ||
**/.DS_Store | ||
.vscode/ | ||
basic.vim | ||
|
||
# custom to dorothy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[settings] | ||
profile=black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Autoformatter friendly markdownlint config (all formatting rules disabled) | ||
default: true | ||
blank_lines: false | ||
bullet: false | ||
html: false | ||
indentation: false | ||
line_length: false | ||
spaces: false | ||
url: false | ||
whitespace: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: 0.1 | ||
cli: | ||
version: 0.8.0-beta | ||
lint: | ||
enabled: | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
#!/usr/bin/env bash | ||
source "$DOROTHY/sources/strict.bash" | ||
|
||
function alias-helper() ( | ||
# ===================================== | ||
# Arguments | ||
|
||
function help { | ||
cat <<-EOF >/dev/stderr | ||
ABOUT: | ||
Wrappers around macOS aliases to make things easier. | ||
USAGE: | ||
alias-helper <action> | ||
ACTIONS: | ||
new -- <alias-file-path> <target-file-path> | ||
Makes a new macOS alias file at the <alias-file-path> pointing to the <target-file-path>. | ||
symlink -- <alias-file-path> | ||
Converts the macOS alias file with its UNIX symlink equivalent. | ||
verify -- <alias-file-path> | ||
Verify the path is a macOS alias file. | ||
target -- <alias-file-path> | ||
Output the target if the path is a macOS alias file. | ||
info -- <alias-file-path> | ||
Human friendly details about the macOS alias file. | ||
EOF | ||
if test "$#" -ne 0; then | ||
echo-error "$@" | ||
fi | ||
return 22 # Invalid argument | ||
} | ||
|
||
# process | ||
local item action='' args=() | ||
while test "$#" -ne 0; do | ||
item="$1" | ||
shift | ||
case "$item" in | ||
'--help' | '-h') help ;; | ||
'--') | ||
args+=("$@") | ||
shift $# | ||
break | ||
;; | ||
'--'*) help "An unrecognised flag was provided: $item" ;; | ||
*) | ||
if test -z "$action"; then | ||
action="$item" | ||
else | ||
help "An unrecognised argument was provided: $item" | ||
fi | ||
;; | ||
esac | ||
done | ||
|
||
# ===================================== | ||
# Actions | ||
|
||
function alias_verify { | ||
local path="$1" | ||
silent-stderr osascript <<-EOF | ||
tell application "Finder" | ||
set theItem to (POSIX file "$path") as alias | ||
if the kind of theItem is "alias" then | ||
get the posix path of ((theItem) as text) | ||
end if | ||
end tell | ||
EOF | ||
} | ||
|
||
function alias_target { | ||
local path="$1" | ||
silent-stderr osascript <<-EOF | ||
tell application "Finder" | ||
set theItem to (POSIX file "$path") as alias | ||
if the kind of theItem is "alias" then | ||
get the POSIX path of ((original item of theItem) as text) | ||
end if | ||
end tell | ||
EOF | ||
} | ||
|
||
function alias_info { | ||
local path="$1" src target | ||
|
||
# verify | ||
src="$(alias_verify "$path" || :)" | ||
if test -z "$src"; then | ||
{ | ||
echo-style \ | ||
--bold+red="$path" \ | ||
$'\t' \ | ||
$'\t' --error='← not an alias' | ||
return 22 # EINVAL Invalid argument | ||
} >/dev/stderr | ||
fi | ||
|
||
# target | ||
target="$(aliastarget "$path" || :)" | ||
if test -z "$target"; then | ||
{ | ||
stderr echo-style \ | ||
--bold="$src" \ | ||
$'\t' \ | ||
$'\t' --error='← target broken' | ||
return 9 # EBADF Bad file descriptor | ||
} >/dev/stderr | ||
fi | ||
if test ! -e "$target"; then | ||
{ | ||
stderr echo-style \ | ||
--bold="$src" \ | ||
--nocolor=$'\t' --color+dim=$'\t→\t' --bold+red="$target" \ | ||
$'\t' --error='← target missing' | ||
return 2 # ENOENT No such file or directory | ||
} >/dev/stderr | ||
fi | ||
|
||
# success | ||
echo-style \ | ||
--bold="$src" \ | ||
--nocolor=$'\t' --color+dim=$'\t→\t' --bold+green="$target" | ||
} | ||
|
||
function alias_new { | ||
local path="$1" target="$2" type target_absolute path_absolute path_directory path_filename | ||
target_absolute="$(fs-absolute "$target")" | ||
path_absolute="$(fs-absolute "$path")" | ||
path_directory="$(dirname "$path_absolute")" | ||
path_filename="$(basename "$path_absolute")" | ||
|
||
# act | ||
if test -d "$target_absolute"; then | ||
type="folder" | ||
elif test -f "$target_absolute"; then | ||
type="file" | ||
else | ||
{ | ||
echo-style --error='Invalid path or unsupported type:' ' ' --code="$path" | ||
return 22 # EINVAL Invalid argument | ||
} >/dev/stderr | ||
fi | ||
|
||
if test -f "$path_absolute"; then | ||
fs-rm "$path_absolute" | ||
fi | ||
|
||
osascript <<-EOF | ||
tell application "Finder" | ||
make new alias to ${type} (posix file "$target_absolute") at (posix file "$path_directory") | ||
set name of result to "$path_filename" | ||
end tell | ||
EOF | ||
|
||
# make the alias's permissions the same as the target's | ||
chmod "$(stat -f '%p' "$target_absolute")" "$path_absolute" | ||
#chmod --reference="$targetPath" "$path_absolute" | ||
} | ||
|
||
function alias_symlink { | ||
local path="$1" src target | ||
|
||
# verify alias | ||
src="$(alias_verify "$path" || :)" | ||
if test -z "$src"; then | ||
{ | ||
echo-style --bold+red="$path" ' ' --error='<- not an alias' | ||
return 22 # EINVAL Invalid argument | ||
} >/dev/stderr | ||
fi | ||
|
||
# verify target | ||
target="$(alias_target "$path" || :)" | ||
if test -z "$target"; then | ||
{ | ||
echo-style --bold="$src" --dim=' → ' --bold+red="$target" ' ' --error='← target broken' | ||
return 9 # EBADF Bad file descriptor | ||
} >/dev/stderr | ||
fi | ||
if test ! -e "$target"; then | ||
{ | ||
echo-style --bold="$src" --dim=' → ' --bold+red="$target" ' ' --error='← target missing' | ||
return 2 # ENOENT No such file or directory | ||
} >/dev/stderr | ||
fi | ||
|
||
# convert | ||
if test -f "$target"; then | ||
ln -nfs "$target" "$src" | ||
echo "converted $path -> $target" | ||
elif test -d "$target"; then | ||
ln -nfs "$target" "$src" | ||
echo "converted $path -> $target" | ||
fi | ||
} | ||
|
||
# ===================================== | ||
# Act | ||
|
||
if test "$(type -t "alias_$action")" = 'function'; then | ||
"alias_$action" "${args[@]}" | ||
return "$?" | ||
else | ||
echo-style --error="Action [$action] not yet implemented." >/dev/stderr | ||
return 78 # Function not implemented | ||
fi | ||
) | ||
|
||
# fire if invoked standalone | ||
if test "$0" = "${BASH_SOURCE[0]}"; then | ||
alias-helper "$@" | ||
fi |
Oops, something went wrong.