Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save firedynasty/c1f896508dd3e1b9a144ce37a3142894 to your computer and use it in GitHub Desktop.
Save firedynasty/c1f896508dd3e1b9a144ce37a3142894 to your computer and use it in GitHub Desktop.
These commands in bash allow you to read through files like a book and you can go to a different placeholder
#going in and out of folders with CD resets the count
function cd() {
local x2 the_new_dir adir index
local -i cnt
if [[ $1 == "--" ]]; then
cd_func4 $OLDPWD
return 1
fi
the_new_dir=$1
[[ -z $1 ]] && the_new_dir=$HOME
if [[ ${1:0:1} == '-' ]]; then
if [ ${#1} -gt 1 ]; then
echo "$(cat /Users/username/desktop/macbook_pro_scripts/echo_files/test_3.txt | head -${1:1:10} | tail -1)" > /Users/username/desktop/macbook_pro_scripts/echo_files/recently_opened.txt
echo "$(cat /Users/username/desktop/macbook_pro_scripts/echo_files/test_3.txt | head -${1:1:10} | tail -1)"
sed -i '' 's!~!/Users/username!g' /Users/username/desktop/macbook_pro_scripts/echo_files/recently_opened.txt
cd "$(cat /Users/username/desktop/macbook_pro_scripts/echo_files/recently_opened.txt)"
return 1
else
coloredEcho 'cdhistory /vimcdhistory' green
cat -n /Users/username/desktop/macbook_pro_scripts/echo_files/test_3.txt
return 1
fi
#
fi
#
# '~' has to be substituted by ${HOME}
[[ ${the_new_dir:0:1} == '~' ]] && the_new_dir="${HOME}${the_new_dir:1}"
#
# Now change to the new dir and add to the top of the stack
pushd "${the_new_dir}" > /dev/null
[[ $? -ne 0 ]] && return 1
the_new_dir=$(pwd)
#
# Trim down everything beyond 11th entry
popd -n +11 2>/dev/null 1>/dev/null
#
# Remove any other occurence of this dir, skipping the top of the stack
for ((cnt=1; cnt <= 10; cnt++)); do
x2=$(dirs +${cnt} 2>/dev/null)
[[ $? -ne 0 ]] && return 0
[[ ${x2:0:1} == '~' ]] && x2="${HOME}${x2:1}"
if [[ "${x2}" == "${the_new_dir}" ]]; then
popd -n +$cnt 2>/dev/null 1>/dev/null
cnt=cnt-1
fi
done
marsh=$(echo $PWD)
if [ "${#marsh}" -gt 30 ]; then
echo $PWD >> /Users/username/desktop/macbook_pro_scripts/echo_files/test_3.txt
echo $PWD >> /Users/username/desktop/macbook_pro_scripts/echo_files/cd_history.txt
fi
length_="$(cat /Users/username/desktop/macbook_pro_scripts/echo_files/test_3.txt | wc -l)"
length_="${length_#"${length_%%[![:space:]]*}"}"
length_="${length_%"${length_##*[![:space:]]}"}"
echo -n 0 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
ls -1U $1 | wc -l > /Users/username/Desktop/macbook_pro_scripts/echo_files/other_test.txt
sed -i -e 's/ //g' /Users/username/Desktop/macbook_pro_scripts/echo_files/other_test.txt
if [ "$length_" -gt 22 ]; then
sed -i '' '1d' /Users/username/desktop/macbook_pro_scripts/echo_files/test_3.txt
sed -i '' '$!N; /^\(.*\)\n\1$/!P; D' /Users/username/desktop/macbook_pro_scripts/echo_files/cd_history.txt
sed -i '' '$!N; /^\(.*\)\n\1$/!P; D' /Users/username/desktop/macbook_pro_scripts/echo_files/test_3.txt
fi
return 0
}
# this is the variable that allows for reading of the next file
# if you don't have pygmentize installed you can use cat instead
function 00(){
if [[ $# -eq 0 ]]; then
current_folder_count=$(cat /Users/username/Desktop/macbook_pro_scripts/echo_files/other_test.txt)
current_folder_count=$(($current_folder_count + 0))
#echo $current_folder_count
second_count=$(cat /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt)
second_count=$((second_count+1))
echo -n $second_count > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
#echo $second_count
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -$second_count | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -$second_count | tail -1)"
if ((second_count < current_folder_count));
then
echo 'so far not exceeded'
else
echo 'exceeded'
fi
else
fi
}
# markers in the folder, reset to the 1st file and so on...
function 01() {
echo -n 1 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -1 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -1 | tail -1)"
}
function 02() {
echo -n 2 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -2 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -2 | tail -1)"
}
function 03() {
echo -n 3 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -3 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -3 | tail -1)"
}
function 04() {
echo -n 4 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -4 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -4 | tail -1)"
}
function 05() {
echo -n 5 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -5 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -5 | tail -1)"
}
function 06() {
echo -n 6 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -6 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -6 | tail -1)"
}
function 07() {
echo -n 7 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -7 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -7 | tail -1)"
}
function 08() {
echo -n 8 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -8 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -8 | tail -1)"
}
function 09() {
echo -n 9 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -9 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -9 | tail -1)"
}
function 10() {
echo -n 10 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -10 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -10 | tail -1)"
}
function 10() {
echo -n 10 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -11 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -11 | tail -1)"
}
function 11() {
echo -n 11 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -12 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -12 | tail -1)"
}
function 12() {
echo -n 12 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -13 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -13 | tail -1)"
}
function 13() {
echo -n 13 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -14 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -14 | tail -1)"
}
function 14() {
echo -n 14 > /Users/username/desktop/macbook_pro_scripts/echo_files/count_open.txt
# attach the number to the file
echo "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -15 | tail -1)"
pygmentize "$(find . -type f -maxdepth 1 -not -path '*/\.*' | sort | head -15 | tail -1)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment