Copy and paste in terminal termux:float - terminal

I know how to copy and paste in termux (https://termux.com/) but it is not the same for termux:float. How to copy and paste in termux:float?

There's no native functionality according to this github issue.
However, you can write a workaround by changing your tmux config as follows:
bind V run-shell "termux-clipboard-get >~/.tmux-buffer-tmp" \; load-buffer -b tmp-copy-buffer ~/.tmux-buffer-tmp \; paste-buffer -b tmp-copy-buffer -d \; run-shell -b "rm ~/.tmux-buffer-tmp"
bind C save-buffer ~/.tmux-buffer-tmp \; run-shell "cat ~/.tmux-buffer-tmp | termux-clipboard-set " \; run-shell -b "rm ~/.tmux-buffer-tmp"

Related

Rename files in multiple subfolders

I have multiple unique directories that each contain a file named filtered_feature_bc_matrix.h5. I want to paste the directory-name onto the filename to make the filename unique within each folder. Is this possible?
./sample_scRNA_unsorted_98433_Primary_bam/outs/filtered_feature_bc_matrix.h5
./sample_scRNA_unsorted_77570_Primary_bam/outs/filtered_feature_bc_matrix.h5
out:
./sample_scRNA_unsorted_98433_Primary_bam/outs/sample_scRNA_unsorted_98433_Primary_bam_filtered_feature_bc_matrix.h5
./sample_scRNA_unsorted_77570_Primary_bam/outs/sample_scRNA_unsorted_77570_Primary_bam_filtered_feature_bc_matrix.h5
For completeness here is a solution with only bash built-in:
shopt -s globstar nullglob
name="filtered_feature_bc_matrix.h5"
for f in */**/"$name"; do mv "$f" "${f%/*}/${f%%/*}_$name"; done
find . -type f -name 'filtered_feature_bc_matrix.h5' \
-exec sh -c \
'fp="$1"; d=$(echo "$fp"|cut -d/ -f2); echo $(dirname "$fp")/${d}_$(basename "$fp")' \
-- '{}' \;
find allows to iterate the files with relative path
-exec allows to do action on '{}' which is the file path
sh is used to simplify the action
dirname and basename allows to extract directories or filename.
cut is used to extract only the first directory (second field as the first one is .)
To rename:
find . -type f -name 'filtered_feature_bc_matrix.h5' \
-exec sh -c \
'fp="$1"; d=$(echo "$fp"|cut -d/ -f2); mv -v "$fp" "$(dirname "$fp")/${d}_$(basename "$fp")"' \
-- '{}' \;

How to kill all tmux windows at the same time using tmux command.?

I created a shell script to start tmux (in Mac)
It used to work but not after upgrade OS and computer
The last command supposed to close all windows and quit.
Any help ? Thanks
tmux new-session \; \
setw -g base-index 1 \; \
setw -g pane-base-index 1 \; \
split-window -h -p 65 \; \
send-keys 'vim' C-m \; \
split-window -h -p 50 \; \
select-pane -t 3 \; \
split-window -v \; \
send-keys 'guard' C-m \; \
select-pane -t 2 \; \
set -g mouse-select-pane on \; \
set -g mouse-resize-pane on \; \
bind-key Q kill-session \;
tmux 3.2a
MacOS Big Sur Version 11.6.2
in ~/.tmux.conf include this line:
bind-key Q kill-session
Now bind-key then Q will exit all

How to make a loop to compile groff documents into a specific folder

I have several .ms documents scattered in different folders and I would like to make a script which compiles each .ms document and output the corresponding .pdf file in a specific folder.
The folder structure is as follow:
/home/user/foo/folder1/file1.ms
/home/user/foo/folder2/file2.ms
/home/user/foo/folder3/file3.ms
...
Here is what I have done so far:
#!/bin/bash
folder="/home/user/foo/"
file=$(du -a "$folder" | grep ".ms" | cut -f2- | sort)
However I don't know how to make the loop that is going to turn each line of the output into the corresponding .pdf file e.g:
/home/user/foo/bar/file1.pdf
/home/user/foo/bar/file2.pdf
/home/user/foo/bar/file3.pdf
...
The groff command I use to compile .ms to .pdf is:
groff -k -T pdf -ms file.ms > file.pdf
EDIT
Thanks to #dash-o answer I have updated my script to this :
#!/bin/bash
input="/home/user/foo/"
output="/home/user/foo/bar"
find $input -name '*.ms' -execdir sh -c 'groff -k -T pdf -ms {} > $output$(basename {} .ms).pdf' \;
However this compiles only the first document and does not place it in the "output" directory but in the same directory as the .ms file and I get "1: Syntax error: ")" unexpected".
On surface, two steps are needed:
Find all the '.ms' files (using find ...)
Convert each one into PDF (using -execdir on the find)
folder=...
find $folder -name '*.ms' -execdir sh -c 'groff -k -t -pdf -ms {} > $(basename {} .ms).pdf' \;
#!/bin/bash
input="/home/matthieu/Documents/Philosophie/L1"
output="/home/matthieu/Documents/Philosophie/L1/S1/Cours"
find "$input" -name '*.ms' -execdir sh -c 'groff -k -T pdf -ms "$1" > "$2/${1%.ms}.pdf"' sh {} "$output" \;

Shnsplit : Find all cue files, split in flacs in the same output directory

I have found this command to split my FLAC files into Tracks from a cue file:
find . -name "*.cue" -exec sh -c 'exec shnsplit -f "$1" -o flac -d "%a" -t "%n_%p-%a-%t" "${1%.cue}.flac"' _ {} \;
It is working flawlessly, the only thing is that the output files are going in the directory from where I am launching the command. Is it possible to tell shnsplit to output the FLAC tracks in the very same directory the .cue file was found?
The -d '%a' does not expand to the current file folder. The '%' escapes are only available for -printf. Consider updating the command to to use dirname on $1:
find . -name "*.cue" -exec sh -c 'exec shnsplit -f "$1" -o flac -d "$(dirname $1)" -t "%n_%p-%a-%t" "${1%.cue}.flac"' _ {} \;
The right command to use is this one :
find . -name "*.cue" -exec sh -c 'exec shnsplit -f "$1" -o flac -d "$(dirname "$1")" -t "%n_%p-%a-%t" "${1%.cue}.flac"' _ {} \;
Thanks for pointing me in the right direction.

Pipe fswatch output into a shell script

I am trying to pipe the output of fswatch to several commands in a shell script with following technique:
$ fswatch -0 [opts] [paths] | xargs -0 -n 1 -I {} [command]
Instead of [command] I put the shell script path. Here is my command line:
fswatch -0 -Ie ".*\.*$" -i ".*\.mp4$" ~/Desktop/encoding\ tests | xargs -0 -n 1 -I {} ~/Desktop/s3cmd.sh
The script is following:
#!/bin/sh
terminal-notifier -message "s3cmd Upload {}" ;
s3cmd sync --acl-public -m video/mp4 --add-header=Cache-Control:public,max-age=2052000 {} s3://saltanat-test/ &&
terminal-notifier -message "s3cmd Upload of {} done"
Sorry I am not experienced with shell scripting.
How can I pipe the the fswatch output into the script?
Thank you.
#!/bin/bash
fswatch -0 -x --event Created --event Updated --event Renamed -Ie '.*\.*$' -i '.*\.mp4$' ~/Desktop/encoding\ tests \
| xargs -0 -n 1 ~/Desktop/s3cmd-3.sh
This works. Thanks.
For anyone in the future with this question :
fswatch command:
fswatch -0 /path/to/watch | xargs -0 -n 1 -I {} ~/yourfile.sh {}
.sh file :
#!/bin/bash
echo $1
Now $1 will be equal to the output of fswatch, which is the full path to the file that was changed.

Resources