Skip to main content

CLI tool for searching file in your PC

Project description

Sefile CLI

SEFILE

Sefile CLI is a personal project created by Faisal Ramadhan or myself. This project was built using the Python programming language. At the time of its creation, this CLI was only useful for finding the desired file according to the initial directory, but over time I started adding several new commands, such as Create, Read, Write and Delete. All of these commands have their own purpose and function.

This CLI tool has available in https://pypi.org/ you can access it in https://pypi.org/project/new-sefile/ from there you can know how this CLI tool was made.

To install this CLI tool, you can simply type on your terminal or CMD:

python3 -m pip install new-sefile

To upgrade the CLI tool to the newest version, you can simply type on your terminal or CMD:

python3 -m pip install --upgrade new-sefile

[!WARNING] To execute this package as a CLI tool, you must first registred the python $PATH for this package. So go check out your directory that save all of your python package. All operating system, has a different path where the python package saved, so search for it in Google first.

For Linux OS & Mac OS:

sudo nano ~/.bashrc

And now you are in .bashrc file, then add new line code, like:

export PATH="/home/(user)/(path)/bin:$PATH

Remember the (path) is different for every linux users, so from me is that you must search first where all you python package was saved. Then you can add new PATH into your python PATH, like above.

There are some different file names, that run executable dotfiles (.file) is your system, such as:

  • .bashrc
  • .profile
  • .bash_profile
  • .zprofile
  • .zlogin
  • .bash_login

So in my opinion, that you must search where the executable file that execute your python package.

For Windows OS:

[!NOTE] For this operating system, i know you can do it by yourself, right?

Requirements

Each project must have additional modules or packages for ease of project creation. I myself use a lot of packages to make this CLI. The modules or packages list that I use is:

  • typing

[!NOTE] if you want more information about this library, see https://docs.python.org/3/library/typing.html

  • fnmatch

[!NOTE] if you want more information about this library, see https://docs.python.org/3/library/fnmatch.html

  • logging

[!NOTE] if you want more information about this library, see https://docs.python.org/3/howto/logging.html

  • os

Info: > if you want more information about this library, see https://docs.python.org/3/library/os.html

  • pathlib

[!NOTE] if you want more information about this library, see https://docs.python.org/3/library/pathlib.html

  • typer

Installation:

python -m pip install "typer[all]"

[!NOTE] if you want more information about this library, see https://typer.tiangolo.com/tutorial/first-steps/

  • rich

[!WARNING] If you do pip install "typer[all]" before, then you don't have to install the rich module.

Installation:

python -m pip install rich

[!NOTE] If you want more information about this library, see https://rich.readthedocs.io/en/stable/introduction.html

  • termcolor

Installation:

python -m pip install termcolor

[!NOTE] if you want more information about this library, see https://github.com/termcolor/termcolor

  • npyscreen

Installation:

python -m pip install npyscreen

[!NOTE] if you want more information about this library, see https://npyscreen.readthedocs.io/introduction.html

  • ascii-magic

Installation:

python -m pip install ascii-magic

[!NOTE] if you want more information about this library, see https://pypi.org/project/ascii-magic/

  • colorama

Installation:

python -m pip install colorama

[!NOTE] if you want more information about this library, see https://pypi.org/project/colorama/

  • Pillow

Installation:

python -m pip install Pillow

[!NOTE] if you want more information about this library, see https://pillow.readthedocs.io/en/stable/

  • art

Installation:

python -m pip install art

[!NOTE] if you want more information about this library, see https://www.ascii-art.site/

How to use it

It's quite easy, you just need to enter the command sefile --help, then you get the output like this:

Screenshot from 2023-09-25 18-04-19

[!NOTE] if you want more information about this library, see https://www.ascii-art.site/

How to use it

It's quite easy, you just need to enter the command python -m sefile --help, then you get the output like this:

How to show CLI version and information?

sefile --version

or

sefile -v

How to find a file?

sefile find <filename>

or

[!NOTE] You can specify the initial directory path to find the file you want.

sefile find <filename> <path>

At first I created this based only on the filename, but eventually I added new flag options, namely --startswith and --endswith.

  • --startswith flag is useful for searching files with your own custom prefix. Usage examples:

[!NOTE] --startswith flag has been set as is_eager=True, meaning this parameter will be executed and the main parameter will be overridden. Also, you need to input from what (path) you want to search file startswith (prefix).

sefile find --startswith main

When you do this, the system will automatically look for files with a certain (in this case main) prefix from each directory or sub-directory that matches the initial directory.

  • --endswith flag is useful for searching files with your own custome prefix. Usage examples:

[!NOTE] --endswith flag has been set as is_eager=True, meaning this parameter will be executed and the main parameter will be overridden.

sefile find --endswith .py

This flag has same functional as --startswith flag, but search file by the end name of the file that match with your custome prefix. Also, you need to input from what (path) you want to search file endswith (prefix).

[!NOTE] --lazy flag has been as is_eager=True, meaning this parameter will be executed and the main parameter will be overridden.

sefile find --lazy

This flag can be use if you to lazy to input CLI command. You only need to enter a special custom query, namely find from . This custom query has same functionality as sefile find command.

There are several input command you can do:

  • find (filename) from (path)

for Linux OS: find main.py from /home/(user)/Documents

for Windows OS: find main.py from C:\Directory\SubDirectory

  • find from (path) startswith (prefix)

for Linux OS: find file from /home/(user)/Documents startswith main

for Windows OS: find file from C:\Directory\SubDirectory startswith main

  • find from (path) like (prefix)

for Linux OS: find file from /home/(user)/Documents like test

for Windows OS: find file from C:\Directory\SubDirectory like test

NOTE: You can also do 'quit' or 'exit' custom query in input field. This situation will needed if you want to cancel the find activity. So it makes more flexible for you to use find command

How to create a file?

sefile create <filename>

[!NOTE] Default directory set as /home/username

or

sefile create <filename> <path>

The system will automatically create a file with a certain file type (according to the type you add at the end of the file) in the directory you enter.

[!NOTE] In newest update, there's one Options called --project. This useful for you if you too lazy for creating simple project. Remember this Options, will create Python, Javascript, or Go project, depends on your choice.

To run --project Options, you just simply write it in your terminal like this below:

sefile create --project

And you got this little thing:

What's project you want to create? 
 >  ๐Ÿ Easy Python                                                                                                                     
    ๐Ÿ‘‘ The king of Javascript                                                                                                          
    ๐Ÿผ Cute Go                                                                                                                         
    โŒ Nah, i'm good         
What's the name of the ๐Ÿ Easy Python project? my_api_project
Where do you want to save this my_api_project? /home/users/Documents

NOTE: You can do 'quit' or 'exit' command in input field. This command so useful if you are in the situation where you don't wanna input anything, or you do wrong input name in project name, or project directory, or when you choose the wrong project what you want to make.

In the newest update, i add another functionality for this create command. It's --write options. To using it, just simply type:

sefile create --write

Screenshot from 2023-09-25 18-05-15

It's automatically displaying Code Editor Interface in your terminal.

[!NOTE] you need specifiy the Filename and Path first, before you do code or creating text.

So this write command, doesn't need ARGS at all, you just input command in your terminal above, and you can do code in your terminal.

INFORMATION:

So if you notice, theres is 'EXIT' button and 'SAVE' button right? the functionality of these 2(two) button are same as 'EXIT' button and 'SAVE' button in your code editor.

You can exit whatever you want, but you can't save the code if you not input value in 'Filename' and 'Folder Path'. So be careful when you use this.

How to read a file?

sefile read <filename> <path>

or

  • --format flag is especially useful for reading files of a certain type. Default file typer set as text or .txt. Example of the output:

Example 1:

Do this command in your terminal:

sefile read <filename> <path> --format python --indent --theme one-dark 

And you get a result like this in your terminal (NOTE: This is just example)

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ experiments.py โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚    1 # ./learn_class/experiments.py                                                                                                 โ”‚
โ”‚    2                                                                                                                                โ”‚
โ”‚    3 import geocoder                                                                                                                โ”‚
โ”‚    4                                                                                                                                โ”‚
โ”‚    5 from dataclasses import dataclass                                                                                              โ”‚
โ”‚    6 from fuzzywuzzy import fuzz, process                                                                                           โ”‚
โ”‚    7 from geopy.geocoders import Nominatim                                                                                          โ”‚
โ”‚    8 from geonamescache import GeonamesCache                                                                                        โ”‚
โ”‚    9 from timezonefinder import TimezoneFinder                                                                                      โ”‚
โ”‚   10                                                                                                                                โ”‚
โ”‚   11 @dataclass                                                                                                                     โ”‚
โ”‚   12 class Experiment:                                                                                                              โ”‚
โ”‚   13 โ”‚                                                                                                                              โ”‚
โ”‚   14 โ”‚   @staticmethod                                                                                                              โ”‚
โ”‚   15 โ”‚   def first_experiment() -> None:                                                                                            โ”‚
โ”‚   16 โ”‚   โ”‚   """                                                                                                                    โ”‚
โ”‚   17 โ”‚   โ”‚   ------------                                                                                                           โ”‚
โ”‚   18 โ”‚   โ”‚   |Definition|                                                                                                           โ”‚
โ”‚   19 โ”‚   โ”‚   ------------                                                                                                           โ”‚
โ”‚   20 โ”‚   โ”‚                                                                                                                          โ”‚
โ”‚   21 โ”‚   โ”‚   This function is useful for tracking the current location by using the user's IP address.                              โ”‚
โ”‚   22 โ”‚   โ”‚   """                                                                                                                    โ”‚
โ”‚   23 โ”‚   โ”‚   locator = Nominatim(user_agent="My App")                                                                               โ”‚
โ”‚   24 โ”‚   โ”‚   my_location = geocoder.ip('me')                                                                                        โ”‚
โ”‚   25 โ”‚   โ”‚   latitude = my_location.geojson['features'][0]['properties']['lat']                                                     โ”‚
โ”‚   26 โ”‚   โ”‚   longtitude = my_location.geojson['features'][0]['properties']['lng']                                                   โ”‚
โ”‚   27 โ”‚   โ”‚                                                                                                                          โ”‚
โ”‚   28 โ”‚   โ”‚   location = locator.reverse(f"{latitude}, {longtitude}")                                                                โ”‚
โ”‚   29 โ”‚   โ”‚   print(f"Your current IP location: {location}")                                                                         โ”‚
โ”‚   30 โ”‚                                                                                                                              โ”‚
โ”‚   31 โ”‚   @staticmethod                                                                                                              โ”‚
โ”‚   32 โ”‚   def second_experiment(city: str) -> None:                                                                                  โ”‚
โ”‚   33 โ”‚   โ”‚   """                                                                                                                    โ”‚
โ”‚   34 โ”‚   โ”‚   ------------                                                                                                           โ”‚
โ”‚   35 โ”‚   โ”‚   |Definition|                                                                                                           โ”‚
โ”‚   36 โ”‚   โ”‚   ------------                                                                                                           โ”‚
โ”‚   37 โ”‚   โ”‚                                                                                                                          โ”‚
โ”‚   38 โ”‚   โ”‚   This function is useful for tracking the current location by simply entering the city inputted by the user.            โ”‚
โ”‚   39 โ”‚   โ”‚   """                                                                                                                    โ”‚
โ”‚   40 โ”‚   โ”‚   geolocator = Nominatim(user_agent='My App')                                                                            โ”‚
โ”‚   41 โ”‚   โ”‚   location = geolocator.geocode(city)                                                                                    โ”‚
โ”‚   42 โ”‚   โ”‚   latitude = location.latitude                                                                                           โ”‚
โ”‚   43 โ”‚   โ”‚   longitude = location.longitude                                                                                         โ”‚
โ”‚   44 โ”‚   โ”‚   print(f"City name: {city}\nLatitude: {latitude}\nLongitude: {longitude}\n")                                            โ”‚
โ”‚   45 โ”‚   โ”‚                                                                                                                          โ”‚
โ”‚   46 โ”‚   โ”‚   timezone = TimezoneFinder()                                                                                            โ”‚
โ”‚   47 โ”‚   โ”‚   timezone_of_the_city = timezone.timezone_at(lat=latitude, lng=longitude)                                               โ”‚
โ”‚   48 โ”‚   โ”‚   print(f"Timezone of {city}: {timezone_of_the_city}")                                                                   โ”‚
โ”‚   49 โ”‚   โ”‚                                                                                                                          โ”‚
โ”‚   50 โ”‚   โ”‚   geonamescache_obj = GeonamesCache()                                                                                    โ”‚
โ”‚   51 โ”‚   โ”‚   cities = [city['name'] for city in geonamescache_obj.get_cities().values()]                                            โ”‚
โ”‚   52 โ”‚   โ”‚   print(cities[:100])                                                                                                    โ”‚
โ”‚   53                                                                                                                                โ”‚
โ”‚   54                                                                                                                                โ”‚
โ”‚   55                                                                                                                                โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

[!NOTE] this is just an example, the output will vary depending on the type of file you entered and the program in the file you entered

If you want to add indent for read code, you just simply add --indent or -i, you can just type like:

sefile read <filename> <path> --format python --indent

If you want to change theme also want to add indent, you can just type like:

sefile read <filename> <path> --format python --indent --theme monokai

All of theme that i add are:

  • one-dark (dark theme)
  • monokai (dark theme)
  • dracula (dark theme)
  • material (dark theme)
  • gruvbox-light (light theme)
  • lightbulb (light theme)

Or you can just type,

sefile read --help

For to know what all themes that available.

How to remove a file?

sefile remove <path> <filename>

So you must input the path directory first then file that inside the directory.

In other hand, this command also has many options. The first one is --startswith or you just simpy type -s. To implement this command, you can type like:

sefile remove <path> --startswith <prefix>

[!NOTE] For --startswith and --endswith options, it must required a prefix that related into this two options. For example, if you want to search file startswith something (depends on what value you inputed), you must use --startswith, but if you want to search file format endswith, let's say .py, then you must use --endswith options.

The second options is --endswith or you just simply type -e. To implement this command, you can type like:

sefile remove <path> --endswith <prefix>

The last one is --subfolder or you just simply type -sf. This options has functionality to remove sub folder and it's content from path directory target. To implement this command, you can type like:

sefile remove <path> --subfolder

Keep in mind

This program is only useful for find, create, read, write and remove. Apart from that, I have nothing to add. I personally will only focus on the main command program, because there are still many things that can be updated in the future.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

new-sefile-0.0.17.tar.gz (30.1 kB view hashes)

Uploaded Source

Built Distribution

new_sefile-0.0.17-py3-none-any.whl (33.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page