This Rust tool simplifies copying a folder to a remote Linux machine by generating shell commands.
Designed for graphical environments (Linux/Windows), it bypasses the need for manual scp/sftp/git workflows by copying terminal commands directly to your clipboard.
- Navigate to the folder you want to copy.
- Run
dir2sh(no parameters or configuration needed). - Paste the generated shell commands on the remote machine.
Example clipboard output:
set +o history
mkdir -p "hello_world"
printf '%s' 'W3BhY2thZ2VdCm5hbWUgPSAiaGVsbG9fd29ybGQiCnZlcnNpb24gPSAiMC4xLjAiCmVkaXRpb24gPSAiMjAyNCIKCltkZXBlbmRlbmNpZXNdCg==' | base64 -d > "hello_world/Cargo.toml"
mkdir -p "hello_world/src"
printf '%s' 'Zm4gbWFpbigpIHsKICAgIHByaW50bG4hKCJIZWxsbywgd29ybGQhIik7Cn0K' | base64 -d > "hello_world/src/main.rs"
set -o historyAfter installing Rust (https://rustup.rs/) you can install this minimalistic tool via:
cargo install dir2sh- This tool is for small folders. Pasting a folder with 100 kilobytes takes around six seconds. You should use
cargo cleanbefore copying Rust projects with this tool e.g. - It won't destroy your
.bash_historybecause ofset +o history.
Fedora:
sudo dnf install xclip
Debian:
sudo apt install xclip
#!/bin/bash
generate_commands() {
local current_dir=$(pwd)
local dir_name=$(basename "$current_dir")
local commands="set +o history\n"
commands+="mkdir -p \"$dir_name\"\n"
while IFS= read -r -d '' file; do
local relative_path="${file#$current_dir/}"
local target_path="$dir_name/$relative_path"
if [[ -d "$file" ]]; then
commands+="mkdir -p \"$target_path\"\n"
elif [[ -f "$file" ]]; then
local encoded=$(base64 -w 0 "$file" 2>/dev/null || base64 -b 0 "$file")
commands+="printf '%s' '$encoded' | base64 -d > \"$target_path\"\n"
fi
done < <(find "$current_dir" -mindepth 1 -print0 2>/dev/null)
commands+="set -o history\n"
echo -e "$commands"
}
if command -v xclip &> /dev/null; then
generate_commands | xclip -selection clipboard
echo "Commands copied to clipboard!"
else
generate_commands
echo "Error: Install xclip."
fi