Just paste the below function inside ~/.bashrc
file and then source(source ~/.bashrc
) it.
google() {
search=""
echo "Googling: $@"
for term in $@; do
search="$search%20$term"
done
xdg-open "http://www.google.com/search?q=$search"
}
After that you can open google search page directly by google search-string
command without pasting the above function everytime on terminal.
The (python) script below creates sub folders and organizes your files into the folders:
Additionally:
- The script calculates the number of folders and adds leading zeros to the folder names for proper sorting (since you mentioned thousands of files, meaning hundreds of folders)
- The number of files per folder may vary, depending on your setting in the head of the script
The script assumes:
- All files have an extension, all files have the same extension
- Your files are named
image1.tiff
, image2.tiff
etc (no leading zeros).
The script
#!/usr/bin/env python3
import os
import math
import shutil
#---
directory = "/path/to/files" # path to your files
n_perfolder = 7 # number of files per sub folder
#--
# creating file list, extension
f_list = os.listdir(directory); ext = f_list[0].split(".")[-1]
# calculate number of folders
n_folders = math.ceil(len(f_list)/n_perfolder)
# creating folder names, including leading zeros
folders = [str(fn+1) for fn in range(n_folders)]
fl_names = [(len(max(folders, key=len))-len(fl))*"0"+fl for fl in folders]
# creating folders and allocate files
for i in range(len(fl_names)):
mkfolder = directory+"/"+fl_names[i]
if not os.path.exists(mkfolder):
os.makedirs(mkfolder)
r = range(i*n_perfolder+1, i*n_perfolder+n_perfolder+1)
for n in r:
try:
file = directory+"/"+"image"+str(n)+"."+ext
target = mkfolder+"/"+"image"+str(n)+"."+ext
shutil.copyfile(file, target)
except FileNotFoundError:
pass
How to use
Copy the script into an empty file, in the head section, set the directory to your files and the number of files per sub directory, save it as organize.py
.
Run it by the command:
python3 /path/to/organize.py
Note
If you'd like to move the files instead of copying, replace the line:
shutil.copyfile(file, target)
by:
shutil.move(file, target)
(mind the indent!)
Best Answer
Intorduction
NOTE: this is a new and updated version of the script, for old version see the edit history of this answer
The script presented below allows to either set a github repository icon or emblem (but not both), as well as reset that metadata back to default. Usage is very simple, as explained by the
-h
option:So if we wanted to recursively search home folder for all
github
repositories and set their emblem, we'd doset_folder_icon.py -e myemblemname -r $HOME
or justcd; set_folder_icon.py -e myemblemname
For best performance, please create
~/bin
directory and store the script there asset_folder_icon.py
. If you want to use it immediately, runsource ~/.bashrc
. If you're using a different shell, ensure that your~/bin
is added to$PATH
variable.NOTE: The script can take any arbitrary file with
--icon
option, but--emblem
requires you to have a specific file to be stored in~/.local/share/icons
with filename something likeemblem-github
. See the The script in action section for an exampleThe script in action
I happen to keep all my github repositories under
~/GIT
folder. In the screenshots below you can see how all github repositores get their emblem set to the custom one.Before:
After:
Script
The script is also available on my personal GitHub repository , where it is more likely to get newer changes and fixes.
Automating the script
Of course, we can run the script manually each time (in fact I'd likely make a function that can combine
git clone
and running this script), although I would recommend that you make the script run each time you log into your GUI session. In order to do that, open the Startup Applications menu, and add the script ( using full path and full filenames is recommended ) as an entry.And next time you log-in your icons will be set.
As for manual idea, you could run
git clone
and the script one after the other with&&
operator, or better yet make a function in~/.bashrc
for that like so: