Skip to content

Instantly share code, notes, and snippets.

@zzhuolun
Created March 13, 2025 16:27
Show Gist options
  • Select an option

  • Save zzhuolun/0d89ce86e3354a57b6667be8e224190a to your computer and use it in GitHub Desktop.

Select an option

Save zzhuolun/0d89ce86e3354a57b6667be8e224190a to your computer and use it in GitHub Desktop.
fish config
set fish_prompt_pwd_dir_length 7
set fish_prompt_pwd_full_dirs 1
set SYNC_DIR /mnt/sync
function s3_to_local_path
echo $SYNC_DIR/(string replace -r 's3://' '' $argv[1])
return 0
end
function local_to_s3_path
echo "s3://"(string replace -r $SYNC_DIR/ '' $argv[1])
return 0
end
function path_handler
if test (count $argv) -ne 1
echo "Error: The input path must have exactly one element"
return 1
end
if string match -q 's3://*' $argv[1]
set s3path $argv[1]
set localpath (s3_to_local_path $s3path)
else if string match -q "$SYNC_DIR*" $argv[1]
set localpath $argv[1]
set s3path (local_to_s3_path $localpath)
else
set localpath (pwd)/$argv[1]
set s3path (local_to_s3_path $localpath)
end
echo $localpath
echo $s3path
return 0
end
function input_handler
if test (count $argv) -eq 0; or string match -q -- '-*' $argv[1]
set -l result (path_handler (pwd)/)
set localpath (echo $result[1])
set s3path (echo $result[2])
set options $argv
else
set -l result (path_handler $argv[1])
set localpath (echo $result[1])
set s3path (echo $result[2])
set options $argv[2..-1]
end
echo $localpath
echo $s3path
echo $options
return 0
end
# Alias for s3ls
function s3ls
set -l result (input_handler $argv)
set s3path (echo $result[2])
set options (echo $result[3..-1])
set cmd "aws s3 ls $s3path --human-readable"
for arg in $options
set cmd "$cmd $arg"
end
echo $cmd
eval $cmd
return 0
end
# Alias for s3sync
function s3sync
set -l result (input_handler $argv)
set localpath (echo $result[1])
set s3path (echo $result[2])
set options (echo $result[3..-1])
set cmd "aws s3 sync $s3path $localpath"
for arg in $options
set cmd "$cmd $arg"
end
echo $cmd
eval $cmd
end
# Alias for s3cp
function s3cp
set -l result (input_handler $argv)
set s3path (echo $result[2])
set localpath (echo $result[1])
set options (echo $result[3..-1])
set cmd "aws s3 cp $s3path $localpath"
for arg in $options
set cmd "$cmd $arg"
end
echo $cmd
eval $cmd
end
# Alias for upload to s3
function s3upload
set -l result (input_handler $argv)
set s3path (echo $result[2])
set localpath (echo $result[1])
set options (echo $result[3..-1])
set cmd "aws s3 cp $localpath $s3path"
for arg in $options
set cmd "$cmd $arg"
end
echo $cmd
eval $cmd
end
function s3cat
set -l result (input_handler $argv)
set s3path (echo $result[2])
set cmd "aws s3 cp $s3path -"
echo $cmd
eval $cmd
end
function s3eog
if test (count $argv) -ne 1
echo "Error: This function requires exactly one argument."
return 1
end
set -l result (input_handler $argv)
set s3path (echo $result[2])
set localpath (echo $result[1])
set cmd "aws s3 cp $s3path $localpath"
for arg in $options
set cmd "$cmd $arg"
end
echo $cmd
eval $cmd
eog $localpath
end
alias clip="xclip -selection clipboard"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment