Skip to content

Instantly share code, notes, and snippets.

@shivams
Created April 15, 2026 08:21
Show Gist options
  • Select an option

  • Save shivams/61f24acb474f862c62b0ea17d2acb0aa to your computer and use it in GitHub Desktop.

Select an option

Save shivams/61f24acb474f862c62b0ea17d2acb0aa to your computer and use it in GitHub Desktop.
Copy-Pasting Across Tmux/Byobu Windows or Different Terminal Windows
# Quite often I have this need that I have multiple terminal or tmux windows open, each in a different directory,
# and I have to copy files from one folder to another. Here is a workflow which smoothens the process.
# Workflow: Mark files using `fmark`, then copy them to another tmux window using `fpaste`. Done. And dusted.
# Requirements: `fzf`
# 1. Mark files using fzf
fmark() {
# Use find (or fd) to list files, fzf -m allows multi-select with Tab
# We convert them to absolute paths so they can be pasted anywhere
local selections=$(find . -maxdepth 1 -mindepth 1 | fzf -m --header "Tab to select multiple, Enter to mark")
if [[ -n "$selections" ]]; then
# Clear the old list and save new absolute paths
echo "$selections" | xargs -I {} realpath "{}" > /tmp/fzf_marked_files
echo "Marked $(wc -l < /tmp/fzf_marked_files) files."
else
echo "No files selected."
fi
}
# 2. Paste marked files to current directory
fpaste() {
if [[ -f /tmp/fzf_marked_files ]]; then
local count=$(wc -l < /tmp/fzf_marked_files)
echo "Copying $count files..."
# Read line by line to handle filenames with spaces correctly
while IFS= read -r file; do
cp -rv "$file" .
done < /tmp/fzf_marked_files
else
echo "No files have been marked!"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment